-
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: change JoinMultiplicity from a Relational prop to a join field #49822
Conversation
I ended up just leaving the multiplicity output code (in expr_format) with the RuleProps, but I'm open to alternative suggestions. One possibility is to give JoinMultiplicity its own expr format flag. |
0bd19a8
to
ad5c6d0
Compare
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.
Nice! I think you should print out the UnfilteredCols
property along with the other RuleProps
. Otherwise just a couple of comments need updating.
Reviewed 21 of 21 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball)
pkg/sql/opt/memo/multiplicity_builder.go, line 83 at r1 (raw file):
} // GetJoinMultiplicity recursively derives the UnfilteredCols field and
GetJoinMultiplicity -> deriveUnfilteredCols
pkg/sql/opt/memo/multiplicity_builder.go, line 84 at r1 (raw file):
// GetJoinMultiplicity recursively derives the UnfilteredCols field and // populates the props.Relational.Rule.MultiplicityProps field as it goes to
this comment is out of date
pkg/sql/opt/memo/testdata/logprops/join, line 2201 at r1 (raw file):
# Regression test for #49821. opt format=show-ruleprops
Since you're showing rule props you should print the unfiltered cols.
pkg/sql/opt/props/logical.go, line 343 at r1 (raw file):
// cannot add any columns, as it may have filtered rows. // // UnfilteredCols is lazily populated by DeriveJoinMultiplicity. It is only
DeriveJoinMultiplicity -> GetJoinMultiplicityFromInputs
b692f07
to
1697c81
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rytaft)
pkg/sql/opt/memo/multiplicity_builder.go, line 83 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
GetJoinMultiplicity -> deriveUnfilteredCols
Done.
pkg/sql/opt/memo/multiplicity_builder.go, line 84 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
this comment is out of date
Done.
pkg/sql/opt/memo/testdata/logprops/join, line 2201 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
Since you're showing rule props you should print the unfiltered cols.
I was worried that this might lead to long output strings, but it actually turned out to be really compact. Done.
pkg/sql/opt/props/logical.go, line 343 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
DeriveJoinMultiplicity -> GetJoinMultiplicityFromInputs
Done.
dedc746
to
56b9015
Compare
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.
Reviewed 17 of 17 files at r2.
Reviewable status: complete! 1 of 0 LGTMs obtained
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.
One thing is that we should only need to derive unfiltered cols in those special cases where we have a self-join or a foreign key join. I realize that would make the logic even more complicated.. But we could at least exit early in some simple cases (no self-joins, and no foreign keys in the tables involved).
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @DrewKimball)
pkg/sql/opt/memo/expr.go, line 452 at r2 (raw file):
// supported (currently InnerJoin, LeftJoin, and FullJoin) to be treated // polymorphically. type multiplicityJoin interface {
Having both multiplicityJoin and JoinMultiplicity is a bit confusing. Maybe change this to joinWithMultiplicity
pkg/sql/opt/memo/expr.go, line 456 at r2 (raw file):
getMultiplicity() props.JoinMultiplicity }
[nit] add some type assertions here to make it clear what types implement it (var _ multiplicityJoin = &InnerJoinExpr{}
)
pkg/sql/opt/memo/expr_format.go, line 696 at r2 (raw file):
tp.Childf("unfiltered-cols: %s", r.UnfilteredCols.String()) } if join, ok := e.(multiplicityJoin); ok {
We have ExprFmtHideMiscProps
, maybe move this in that block
pkg/sql/opt/memo/multiplicity_builder.go, line 33 at r2 (raw file):
right := t.Child(1).(RelExpr) filters := *t.Child(2).(*FiltersExpr) multiplicity := GetJoinMultiplicityFromInputs(t.Op(), left, right, filters)
[nit] DeriveJoinMultiplicityFromInputs would be a better name for this one
56b9015
to
0d75303
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @rytaft)
pkg/sql/opt/memo/expr.go, line 452 at r2 (raw file):
Previously, RaduBerinde wrote…
Having both multiplicityJoin and JoinMultiplicity is a bit confusing. Maybe change this to
joinWithMultiplicity
Done.
pkg/sql/opt/memo/expr.go, line 456 at r2 (raw file):
Previously, RaduBerinde wrote…
[nit] add some type assertions here to make it clear what types implement it (
var _ multiplicityJoin = &InnerJoinExpr{}
)
Done.
pkg/sql/opt/memo/expr_format.go, line 696 at r2 (raw file):
Previously, RaduBerinde wrote…
We have
ExprFmtHideMiscProps
, maybe move this in that block
Done. This causes JoinMultiplicity to be outputted more often though, is that ok?
pkg/sql/opt/memo/multiplicity_builder.go, line 33 at r2 (raw file):
Previously, RaduBerinde wrote…
[nit] DeriveJoinMultiplicityFromInputs would be a better name for this one
Done.
I like that idea. I've got a PR coming after this one that will add a few performance improvements for this library; I'll implement this idea there. |
pkg/sql/opt/memo/expr_format.go, line 696 at r2 (raw file): Previously, DrewKimball (Drew Kimball) wrote…
It doesn't seem less important than the other "misc props", I'd say yes |
0d75303
to
84abbba
Compare
bors r+ |
Merge conflict (retrying...) |
2 similar comments
Merge conflict (retrying...) |
Merge conflict (retrying...) |
84abbba
to
24f44d1
Compare
Canceled |
Previously, the JoinMultiplicity property was stored as a Relational prop. This is a problem because all expressions in a memo group share the same Relational props during exploration, and there are exploration rules that can flip a join's left/right multiplicity. This patch instead stores JoinMultiplcity as a join field that is initialized during construction of the join. This fixes the shared Relational props issue, and also makes it possible for JoinMultiplicity to aid in calculating other logical properties. Fixes cockroachdb#49821 Release note: None
24f44d1
to
ab412e1
Compare
bors r+ |
Build failed (retrying...) |
Build succeeded |
Previously, the JoinMultiplicity property was stored as a Relational
prop. This is a problem because all expressions in a memo group share
the same Relational props during exploration, and there are exploration
rules that can flip a join's left/right multiplicity.
This patch instead stores JoinMultiplcity as a join field that is
initialized during construction of the join. This fixes the shared
Relational props issue, and also makes it possible for JoinMultiplicity
to aid in calculating other logical properties.
Fixes #49821
Release note: None