Skip to content

harness.UseServer() can change the plans generated #2999

@jycor

Description

@jycor

The plans generated from TestSingleScript with and without harness.UseServer() can differ. This is a result of ComPrepare, which extracts literals and replaces them with BindVars, to be later substituted back in. As a result, Projections that used to be Project(Literal(...)) become Project(Alias(Literal(...))). This can affect certain analyzer rules that make decisions based on these Aliases.

For example:

create table t (i int primary key, j int);
insert into t values (123, 456);
update t set j = 999 where i in (select 123);

Without UseServer, the rule unnestInSubqueries detects that the subquery (select 123) is cacheable, doesn't reference any other variables, and other stuff that I don't know, and optimizes the plan to be Filter(Join(...)). Later on, modifyUpdateExprsForJoin sees the join and turn this into an UpdateJoin.

With UseServer, the rule unnestInSubqueries doesn't do this. It cannot resolve the alias/bindvar :v2, so none of these optimizations are applied.

It's very possible other rules are affected by this, resulting in possible performance discrepancies using ComPrepare.

It's not entirely clear to me what should happen here.
Should all rules be able to detect and handle when there are BindVars?
Should BindVars be eliminated before analysis, so it is unaffected?
Leave it be?

Discovered from this issue.

This is left here as I'm not sure what the implications are on Dolt's server side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions