-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: add exploration rule for constraining scans #24355
Conversation
Very nice, mostly nits from me.
It's exciting to see our 2nd exploration rule come online, especially with as big of an impact as this rule will have.
Review status: 0 of 39 files reviewed at latest revision, all discussions resolved, all commit checks successful. pkg/sql/opt/exec/execbuilder/testdata/select, line 11 at r1 (raw file):
I think it'd be good to have a few exec tests that are testing data types other than int, just to make sure they're working end-to-end. pkg/sql/opt/idxconstraint/index_constraints.go, line 669 at r1 (raw file):
NIT: need space before "calculates" pkg/sql/opt/norm/testdata/bool, line 201 at r1 (raw file):
It seems redundant to show "constrained" here when the constraint is also shown below. pkg/sql/opt/optgen/cmd/optgen/explorer_gen.go, line 88 at r1 (raw file):
NIT: It'd be more consistent if we also renamed pkg/sql/opt/xform/explorer.go, line 198 at r1 (raw file):
You can delete this, since you got Optgen generating the code correctly... pkg/sql/opt/xform/explorer.go, line 288 at r1 (raw file):
NIT: could use a header comment pkg/sql/opt/xform/explorer.go, line 293 at r1 (raw file):
NIT: could use a header comment that gives overview of what's going on in this logic pkg/sql/opt/xform/explorer.go, line 298 at r1 (raw file):
NIT: I'd add a comment at the top of this block: pkg/sql/opt/xform/rules/select.opt, line 10 at r1 (raw file):
NIT: I usually put ops with multiple args on multiple lines, just so they're easier to read:
pkg/sql/opt/xform/testdata/physprops/ordering, line 72 at r1 (raw file):
These tests need to be updated so that the pkg/sql/opt/xform/testdata/physprops/ordering, line 151 at r1 (raw file):
Same goes with these tests. pkg/sql/opt/xform/testdata/physprops/presentation, line 31 at r1 (raw file):
And these tests as well. pkg/sql/opt/xform/testdata/rules/scan, line 135 at r1 (raw file):
NIT: I've generally avoided checking in Comments from Reviewable |
Review status: 0 of 39 files reviewed at latest revision, 13 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/private_storage.go, line 179 at r1 (raw file):
Why not write this value before Comments from Reviewable |
Review status: 0 of 39 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful. pkg/sql/opt/xform/testdata/rules/select, line 38 at r1 (raw file):
Drive-by comment: it took me a while to track down what these lines were indicating. Can the root of the memo be indicated inline below? For example, Comments from Reviewable |
pkg/sql/opt/xform/testdata/rules/select, line 38 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I think that for display purposes, we should topologically sort the memo and hide orphan groups (like 10 here). I agree the physical prop strings could be less cryptic too. I will explore these improvements in a separate PR. Comments from Reviewable |
pkg/sql/opt/norm/testdata/bool, line 201 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Right, but it's definitely needed in the Comments from Reviewable |
Review status: 0 of 39 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. pkg/sql/opt/xform/testdata/rules/select, line 38 at r1 (raw file): Previously, RaduBerinde wrote…
Ack. Definitely not for this PR. Comments from Reviewable |
Review status: 0 of 39 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. pkg/sql/opt/norm/testdata/bool, line 201 at r1 (raw file): Previously, RaduBerinde wrote…
Hm, I see. Let's leave as-is for now, and see how we like it, or if we have other ideas later. Comments from Reviewable |
f1bebf8
to
e88949a
Compare
TFTR! Updated. Review status: 0 of 39 files reviewed at latest revision, 15 unresolved discussions, some commit checks failed. pkg/sql/opt/exec/execbuilder/testdata/select, line 11 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/idxconstraint/index_constraints.go, line 669 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/memo/private_storage.go, line 179 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/optgen/cmd/optgen/explorer_gen.go, line 88 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/explorer.go, line 198 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/explorer.go, line 288 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/explorer.go, line 293 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/explorer.go, line 298 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/rules/select.opt, line 10 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/testdata/physprops/ordering, line 72 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/testdata/physprops/ordering, line 151 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/testdata/physprops/presentation, line 31 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Done. pkg/sql/opt/xform/testdata/rules/scan, line 135 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Removed. Comments from Reviewable |
Reviewed 27 of 39 files at r1, 13 of 13 files at r2. pkg/sql/opt/exec/factory.go, line 45 at r1 (raw file):
[nit] add a comment about the purpose of indexConstraint if it's not nil pkg/sql/opt/exec/execbuilder/testdata/select, line 90 at r2 (raw file):
this span looks like it represents str < 'moo' pkg/sql/opt/norm/testdata/bool, line 326 at r2 (raw file):
update comment pkg/sql/opt/xform/explorer.go, line 248 at r2 (raw file):
thegiven -> the given pkg/sql/opt/xform/testdata/rules/select, line 44 at r2 (raw file):
Probably a dumb question: Why is a new group created for (scan a) when group 1 already exists? Comments from Reviewable |
Review status: all files reviewed at latest revision, 20 unresolved discussions, some commit checks failed. pkg/sql/opt/xform/testdata/rules/select, line 44 at r2 (raw file): Previously, rytaft wrote…
We don't show the "needed columns" in the memo, but if we did, you'd see that the needed cols for group #8 are different than group #1. Changing the output columns changes the logical equivalence of the expression, so it has to go into a different group. We do need work on the Comments from Reviewable |
pkg/sql/opt/xform/testdata/rules/select, line 44 at r2 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Got it - thanks for the explanation! Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. pkg/sql/opt/xform/testdata/rules/scan, line 135 at r1 (raw file): Previously, RaduBerinde wrote…
It's fine to leave this as an Comments from Reviewable |
e88949a
to
bee4d01
Compare
New "constrain scan" explore rule tries to push filters into scans, as constraints. The result is either just the constrained scan (if the filter was fully converted into a constraint), or a select on top of the constrained scan. Along with the rule, we needed some minor changes on the execution side to support scan constraints. Other fixes that were necessary: - optgen: the generated code for explore rules was adding expressions to the wrong group (because of shadowing of the original `_eid`). - idxconstraint support for `FiltersOp`. - move the idxconstraint test to `idxconstraint_test` package to avoid import loop. - test catalog fix: the primary index was returning the wrong ordinal value. - adding some cost to the select operator, to prefer a constrained scan with no remaining filter (vs a constrained scan with a remaining filter). Release note: None
bee4d01
to
a4d44ac
Compare
bors r+ |
Build failed |
bors r+ |
24355: opt: add exploration rule for constraining scans r=RaduBerinde a=RaduBerinde New "constrain scan" explore rule tries to push filters into scans, as constraints. The result is either just the constrained scan (if the filter was fully converted into a constraint), or a select on top of the constrained scan. Along with the rule, we needed some minor changes on the execution side to support scan constraints. Other fixes that were necessary: - optgen: the generated code for explore rules was adding expressions to the wrong group (because of shadowing of the original `_eid`). - idxconstraint support for `FiltersOp`. - move the idxconstraint test to `idxconstraint_test` package to avoid import loop. - test catalog fix: the primary index was returning the wrong ordinal value. - adding some cost to the select operator, to prefer a constrained scan with no remaining filter (vs a constrained scan with a remaining filter). Release note: None
Build succeeded |
New "constrain scan" explore rule tries to push filters into scans,
as constraints. The result is either just the constrained scan (if the
filter was fully converted into a constraint), or a select on top of
the constrained scan.
Along with the rule, we needed some minor changes on the execution
side to support scan constraints.
Other fixes that were necessary:
optgen: the generated code for explore rules was adding expressions
to the wrong group (because of shadowing of the original
_eid
).idxconstraint support for
FiltersOp
.move the idxconstraint test to
idxconstraint_test
package to avoidimport loop.
test catalog fix: the primary index was returning the wrong ordinal
value.
adding some cost to the select operator, to prefer a constrained
scan with no remaining filter (vs a constrained scan with a
remaining filter).
Release note: None