-
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 weak keys and rule to eliminate DISTINCT #24451
Conversation
Reviewed 32 of 32 files at r1, 7 of 7 files at r2. pkg/sql/opt/metadata_column.go, line 87 at r1 (raw file):
it contains -> they contain pkg/sql/opt/memo/logical_props.go, line 74 at r1 (raw file):
key it implies -> key implies pkg/sql/opt/memo/logical_props_factory.go, line 365 at r1 (raw file):
coy -> copy pkg/sql/opt/memo/logical_props_factory.go, line 371 at r1 (raw file):
why not make the capacity Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/logical_props.go, line 63 at r1 (raw file):
I would add Note that in some cases, we can have what for all intents and purposes is a (strong) key even though some columns are nullable. For example DISTINCT de-duplicates between NULLs like any other value so the output of DISTINCT always has a key, regardless of nullability. I doubt these cases are important enough to support (it would require keeping track of strong keys explicitly) but maybe we should keep the definition general. pkg/sql/opt/memo/logical_props.go, line 69 at r1 (raw file):
This is ambiguous, they have to have non-NULL values just on these specific columns. Maybe define it like key but with the assumption that NULL does not equal NULL. pkg/sql/opt/memo/logical_props.go, line 74 at r1 (raw file):
I'd say just "empty key" (set suggests you're talking about the entire WeakKeys) Comments from Reviewable |
Review status: all files reviewed at latest revision, 7 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/testdata/logprops/groupby, line 56 at r1 (raw file):
What does this mean? A key with no columns? pkg/sql/opt/memo/testdata/logprops/join, line 136 at r1 (raw file):
Is this correct?
The
Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/testdata/logprops/groupby, line 56 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
yeah. empty key = single row Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/logical_props_factory.go, line 243 at r1 (raw file):
Here we actually want to add pkg/sql/opt/memo/logical_props_factory.go, line 389 at r1 (raw file):
If all keys were "good", filtered is nil here, we do the Add on it and we are effectively dropping all the other keys. I don't think the minor optimization is worth the Comments from Reviewable |
pkg/sql/opt/memo/logical_props_factory.go, line 389 at r1 (raw file): Previously, RaduBerinde wrote…
Ah, sorry, if additional is non-empty, filtered can't be nil here. Comments from Reviewable |
pkg/sql/opt/memo/logical_props_factory.go, line 243 at r1 (raw file): Previously, RaduBerinde wrote…
Sorry, missed that we already checked for that above. Comments from Reviewable |
Review status: 17 of 39 files reviewed at latest revision, 11 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/logical_props_factory.go, line 196 at r4 (raw file):
[nit] Add a TODO to detect keys when we can (for example, if the equality columns are keys on both sides) pkg/sql/opt/memo/logical_props_factory.go, line 228 at r4 (raw file):
Nice. Comments from Reviewable |
Review status: 17 of 39 files reviewed at latest revision, 13 unresolved discussions, all commit checks successful. pkg/sql/opt/memo/logical_props_factory.go, line 196 at r4 (raw file): Previously, RaduBerinde wrote…
+1. I think there are some other cases here too. For instance, an inner join where the join condition is a key in either the left or right relation. I'm not sure if I have that right. I haven't thought about how keys propagate through joins recently and I punted on doing this in opttoy. Might be worthwhile searching literature or other systems to see if they have a list of rules. Comments from Reviewable |
pkg/sql/opt/memo/logical_props_factory.go, line 196 at r4 (raw file): Previously, petermattis (Peter Mattis) wrote…
You can only do that if you know that each row on the key side won't get matched with multiple rows on the other side. E.g. One way to know that is if it's a key on both sides, there may be others.. Comments from Reviewable |
Add a new WeakKeys logical property. Weak keys are derived from unique indexes and sometimes from operators (e.g. GroupBy). Cache the weak keys in metadata and propagate them through various relational operators. Release note: None
Review status: 17 of 39 files reviewed at latest revision, 13 unresolved discussions, all commit checks successful. pkg/sql/opt/metadata_column.go, line 87 at r1 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/memo/logical_props.go, line 63 at r1 (raw file): Previously, RaduBerinde wrote…
I grabbed this definition from opttoy. I did some tweaking to it to incorporate your feedback. pkg/sql/opt/memo/logical_props.go, line 69 at r1 (raw file): Previously, RaduBerinde wrote…
See if my comment rewrite addresses your concerns. pkg/sql/opt/memo/logical_props.go, line 74 at r1 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/memo/logical_props.go, line 74 at r1 (raw file): Previously, RaduBerinde wrote…
Done. pkg/sql/opt/memo/logical_props_factory.go, line 365 at r1 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/memo/logical_props_factory.go, line 371 at r1 (raw file): Previously, rytaft wrote…
I got rid of this for other reasons. pkg/sql/opt/memo/logical_props_factory.go, line 389 at r1 (raw file): Previously, RaduBerinde wrote…
I changed the logic to do it differently. See what you think. pkg/sql/opt/memo/logical_props_factory.go, line 196 at r4 (raw file): Previously, RaduBerinde wrote…
Done. pkg/sql/opt/memo/testdata/logprops/groupby, line 56 at r1 (raw file): Previously, RaduBerinde wrote…
pkg/sql/opt/memo/testdata/logprops/join, line 136 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Good catch, it's wrong. It's only OK in case where the inner-join predicate compares two weak keys for equality. For now, I'll just remove the join weakkey logic, and we can circle back once we start taking predicates into account. Comments from Reviewable |
Add a new EliminateDistinct rule. EliminateDistinct discards a GroupBy operator that is eliminating duplicate rows by using grouping columns that are statically known to form a strong key. By definition, a strong key does not allow duplicate values, so the GroupBy is redundant and can be eliminated. Release note: None
Reviewed 17 of 32 files at r1, 14 of 22 files at r3, 8 of 8 files at r6. Comments from Reviewable |
This PR contains two commits, the first to track weak keys in expressions, and the second to use that information to eliminate unnecessary DISTINCT group by operators.