-
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: Hoist Exists operator and try to decorrelate #24969
Conversation
Review status: 0 of 25 files reviewed at latest revision, all discussions resolved. pkg/sql/opt/norm/rules/join.opt, line 114 at r2 (raw file):
I believe the transformation in [3] is pkg/sql/opt/norm/rules/select.opt, line 234 at r2 (raw file):
Nice! These transformations are quite pleasant to read. pkg/sql/opt/norm/testdata/join, line 304 at r2 (raw file):
🎉 Comments from Reviewable |
Reviewed 14 of 14 files at r1. pkg/sql/opt/memo/logical_props_factory.go, line 130 at r1 (raw file):
Should this line be outside of the pkg/sql/opt/memo/logical_props_factory.go, line 155 at r1 (raw file):
I don't think this check is necessary -- pkg/sql/opt/memo/logical_props_factory.go, line 209 at r1 (raw file):
I don't think this check is necessary -- pkg/sql/opt/memo/logical_props_factory.go, line 252 at r1 (raw file):
[nit] to make this match the logic above, you could just do
pkg/sql/opt/memo/logical_props_factory.go, line 343 at r1 (raw file):
you miss the inputProps outer cols if there are no outer cols in the limit. pkg/sql/opt/memo/logical_props_factory.go, line 362 at r1 (raw file):
ditto Comments from Reviewable |
Great stuff! Review status: 14 of 25 files reviewed at latest revision, 9 unresolved discussions. pkg/sql/opt/memo/logical_props_factory.go, line 130 at r1 (raw file): Previously, rytaft wrote…
Note that pkg/sql/opt/norm/factory.go, line 187 at r2 (raw file):
[nit] add a comment saying that if the list doesn't contain the element, we panic here pkg/sql/opt/norm/testdata/select, line 821 at r2 (raw file):
[nit] it is one of pkg/sql/opt/norm/testdata/select, line 827 at r2 (raw file):
What is missing for pkg/sql/opt/norm/testdata/select, line 918 at r2 (raw file):
I don't think this is correct. This will for example output all rows where The filters should stay inside the left input. We could do that by adjusting the rule:
pkg/sql/opt/ops/scalar.opt, line 66 at r2 (raw file):
[nit] maybe mention that this is equivalent to Comments from Reviewable |
This is exciting to see! Reviewed 11 of 11 files at r2. pkg/sql/opt/norm/rules/select.opt, line 178 at r2 (raw file):
I think you meant -- this only works if this is not an instance of the scalar GroupBy pkg/sql/opt/norm/rules/select.opt, line 228 at r2 (raw file):
semi-joins -> anti-joins pkg/sql/opt/norm/testdata/join, line 367 at r2 (raw file):
why does this only show outer=(1) instead of outer=(1, 2)? pkg/sql/opt/norm/testdata/scalar, line 450 at r2 (raw file):
maybe also add a test for scalar group by to show that it doesn't get eliminated? Comments from Reviewable |
Now that we have support for subqueries, column references to outer relations are possible. This commit calculates the OuterCols logical property for the various relational operators. Release note: None
TFTR, I've made quite a few changes in response to comments, and fixed a few additional bugs that I found while making all the changes as well. Review status: 12 of 25 files reviewed at latest revision, 18 unresolved discussions. pkg/sql/opt/memo/logical_props_factory.go, line 130 at r1 (raw file): Previously, rytaft wrote…
This is a small optimization to avoid an allocation in the >64 cols case. We inherit the pkg/sql/opt/memo/logical_props_factory.go, line 155 at r1 (raw file): Previously, rytaft wrote…
See above comment. pkg/sql/opt/memo/logical_props_factory.go, line 209 at r1 (raw file): Previously, rytaft wrote…
See above comment. pkg/sql/opt/memo/logical_props_factory.go, line 252 at r1 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/memo/logical_props_factory.go, line 343 at r1 (raw file): Previously, rytaft wrote…
They're copied from the input in that case. No need for an extra allocation in that 99% case. pkg/sql/opt/memo/logical_props_factory.go, line 362 at r1 (raw file): Previously, rytaft wrote…
See above comment. pkg/sql/opt/norm/factory.go, line 187 at r2 (raw file): Previously, RaduBerinde wrote…
Done. pkg/sql/opt/norm/rules/join.opt, line 114 at r2 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/sql/opt/norm/rules/select.opt, line 178 at r2 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/norm/rules/select.opt, line 228 at r2 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/norm/testdata/join, line 367 at r2 (raw file): Previously, rytaft wrote…
This is a bug in pkg/sql/opt/norm/testdata/scalar, line 450 at r2 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/norm/testdata/select, line 821 at r2 (raw file): Previously, RaduBerinde wrote…
Done. pkg/sql/opt/norm/testdata/select, line 827 at r2 (raw file): Previously, RaduBerinde wrote…
I added this case to this rule as well as the pkg/sql/opt/norm/testdata/select, line 918 at r2 (raw file): Previously, RaduBerinde wrote…
You're right. I just pulled this rule from opttoy (where it wasn't tested) and didn't think about it enough. I modified this rule according to your suggestion and added some more tests as well. pkg/sql/opt/ops/scalar.opt, line 66 at r2 (raw file): Previously, RaduBerinde wrote…
Done. Comments from Reviewable |
Review status: 12 of 25 files reviewed at latest revision, 12 unresolved discussions. Comments from Reviewable |
Reviewed 1 of 13 files at r3, 12 of 12 files at r4. pkg/sql/opt/memo/logical_props_factory.go, line 130 at r1 (raw file): Previously, andy-kimball (Andy Kimball) wrote…
Oops missed the assignment above. Thanks for the explanation! pkg/sql/opt/norm/rules/join.opt, line 54 at r4 (raw file):
Can you update the comment to explain why semi-joins are eligible but anti-joins are not? Comments from Reviewable |
Transform EXISTS clause in WHERE clauses into a SemiJoinApply or AntiSemiJoinApply operator. Additional rules will attempt to decorrelate the right operand of the Apply by pushing the Apply down through any Select operator. Example: SELECT * FROM a WHERE EXISTS(SELECT * FROM b WHERE a.x=b.x) => SELECT * FROM a SEMI JOIN APPLY (SELECT * FROM b WHERE a.x=b.x) => SELECT * FROM a SEMI JOIN b WHERE a.x=b.x Release note: None
bors r+ |
24969: opt: Hoist Exists operator and try to decorrelate r=andy-kimball a=andy-kimball This PR has two commits for easier review. The first adds support for OuterCols as a relational property. The second uses that to implement transforming the Exists operator into a SemiJoinApply operator, and then attempting to decorrelate that. 25034: storage: bump LastHeartbeat timestamp when writing txn record r=nvanbenschoten a=nvanbenschoten Fixes #23945. See #20448. This change addresses a case where delayed BeginTxn requests can result in txn records looking inactive immediately upon being written. We now bump the txn record's LastHeartbeat timestamp when writing the record. Release note: None Co-authored-by: Andrew Kimball <[email protected]> Co-authored-by: Nathan VanBenschoten <[email protected]>
Build succeeded |
This PR has two commits for easier review. The first adds support for OuterCols as a relational property. The second uses that to implement transforming the Exists operator into a SemiJoinApply operator, and then attempting to decorrelate that.