-
Notifications
You must be signed in to change notification settings - Fork 4k
wip: opt: attempt at building routine parameters as placeholders #158407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The `optimizer_build_routine_params_as_placeholders` session setting has been added. It currently has no effect on any behavior. It will be fully implemented in a future commit. Release note: None
`optbuilder.Builder` has a new method for synthesizing columns that represent reference to routine parameters, called `synthesizeParameterColumn`. Release note: None
Routine parameter references have always been represented as columns in optimizer expressions. They are considered outer columns because no expression within a routine statement produces them. One consequence of this is that, when a routine statement is built, normalization rules might leave the expression tree in a state that cannot be fully optimized later. For example, decorrelation rules can pull filters with parameter references up and away from base relations. As another example, filter push-down rules may fail to push a filter referencing a parameter down towards a scan. In both cases, when the parameter references are replaced with constant values, those filters cannot be pushed into scans and lookup joins because that are not adjacent to based relations. The `optimizer_build_routine_params_as_placeholders` session setting, when enabled, instructs the optimizer to build parameter reference columns that are outside the current scope as placeholders instead of columns. This prevents rules from treating parameter references as outer columns and misguidedly transforming the expression tree. Informs cockroachdb#157840 Release note (performance improvement): The `optimizer_build_routine_params_as_placeholders` session setting has been added. It is disabled by default. When enabled, it may lead to better query plans for statements within user-defined functions and stored-procedures.
|
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
| │ │ │ │ │ │ │ │ │ └── columns: crdb_internal.kv_catalog_comments.classoid:176!null crdb_internal.kv_catalog_comments.objoid:177!null crdb_internal.kv_catalog_comments.objsubid:178!null crdb_internal.kv_catalog_comments.description:179!null | ||
| │ │ │ │ │ │ │ │ └── filters | ||
| │ │ │ │ │ │ │ │ ├── crdb_internal.kv_catalog_comments.classoid:176 != 4294967075 [outer=(176), constraints=(/176: (/NULL - /4294967074] [/4294967076 - ]; tight)] | ||
| │ │ │ │ │ │ │ │ └── crdb_internal.kv_catalog_comments.objoid:177 = c.oid:1 [outer=(1,177), constraints=(/1: (/NULL - ]; /177: (/NULL - ]), fd=(1)==(177), (177)==(1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, any idea why the regression here? It's not obvious to me why we're suddenly not decorrelating.
sql: add optimizer_build_routine_params_as_placeholders
The
optimizer_build_routine_params_as_placeholderssession setting hasbeen added. It currently has no effect on any behavior. It will be fully
implemented in a future commit.
Release note: None
opt: refactor parameter column synthesis
optbuilder.Builderhas a new method for synthesizing columns thatrepresent reference to routine parameters, called
synthesizeParameterColumn.Release note: None
opt: implement optimizer_build_routine_params_as_placeholders
Routine parameter references have always been represented as columns in
optimizer expressions. They are considered outer columns because no
expression within a routine statement produces them. One consequence of
this is that, when a routine statement is built, normalization rules
might leave the expression tree in a state that cannot be fully
optimized later.
For example, decorrelation rules can pull filters with parameter
references up and away from base relations. As another example, filter
push-down rules may fail to push a filter referencing a parameter down
towards a scan. In both cases, when the parameter references are
replaced with constant values, those filters cannot be pushed into scans
and lookup joins because that are not adjacent to based relations.
The
optimizer_build_routine_params_as_placeholderssession setting,when enabled, instructs the optimizer to build parameter reference
columns that are outside the current scope as placeholders instead of
columns. This prevents rules from treating parameter references as outer
columns and misguidedly transforming the expression tree.
Informs #157840
Release note (performance improvement): The
optimizer_build_routine_params_as_placeholderssession setting hasbeen added. It is disabled by default. When enabled, it may lead to
better query plans for statements within user-defined functions and
stored-procedures.
wip