opt: eliminate nested subquery expression#161891
opt: eliminate nested subquery expression#161891DrewKimball wants to merge 1 commit intocockroachdb:masterfrom
Conversation
When one subquery is nested inside of another with no intervening expressions (other than the Values the nested subquery is embedded in), it is possible to replace the parent with the child. This may improve performance and make other optimizations possible for complex PL/pgSQL routines. Informs cockroachdb#160836 Release note: None
yuzefovich
left a comment
There was a problem hiding this comment.
Nice, sounds reasonable to me.
@yuzefovich reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball).
michae2
left a comment
There was a problem hiding this comment.
Might be good to add a couple more cases where the cardinality of the subquery is unknown and the subquery produces more than one row or more than one column.
Might also be good to add a case or two with VALUES () or (SELECT) where the rule shouldn't apply.
@michae2 reviewed 2 files and all commit messages, and made 3 comments.
Reviewable status:complete! 2 of 0 LGTMs obtained (waiting on @DrewKimball).
pkg/sql/opt/norm/rules/scalar.opt line 299 at r1 (raw file):
# single-row, single-column Values expression in the parent subquery. [EliminateNestedSubquery, Normalize] (Subquery (Values [ (Tuple [ $subquery:(Subquery) ]) ]))
Is the inner subquery ever allowed to produce more than one row or column?
pkg/sql/opt/norm/testdata/rules/scalar line 1285 at r1 (raw file):
├── fd: ()-->(3) └── tuple └── subquery
Should there be a max1-row operator somewhere in this plan?
(Oh, maybe we only add that if cardinality is > 1?)
When one subquery is nested inside of another with no intervening expressions (other than the Values the nested subquery is embedded in), it is possible to replace the parent with the child. This may improve performance and make other optimizations possible for complex PL/pgSQL routines.
Informs #160836
Release note: None