-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: add the functional dependency for Datasource, proj, select, agg #33071
planner: add the functional dependency for Datasource, proj, select, agg #33071
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
404db64
to
7433d71
Compare
7433d71
to
ba60938
Compare
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/195153f832affa3f6810f468f4d56723c869de45 |
cf33ad7
to
b357c0e
Compare
// which can upgrade lax FDs to strict ones. | ||
func (s *FDSet) MakeNotNull(notNullCols FastIntSet) { | ||
notNullCols.UnionWith(s.NotNullCols) | ||
notNullColsSet := s.closureOfEquivalence(notNullCols) |
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.
Do we need to exclude lax equivalence in it?
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.
This time we only maintain the strict equiv classes.
planner/funcdep/fd_graph.go
Outdated
if fd.from.SubsetOf(notNullColsSet) && fd.to.SubsetOf(notNullColsSet) { | ||
// we don't need to clean the old lax FD because when adding the corresponding strict one, the lax | ||
// one will be implied by that and itself is removed. | ||
s.AddStrictFunctionalDependency(fd.from, fd.to) |
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.
Seems it's possible that it's an equivalence here.
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.
And, since we don't maintain the lax equiv classes, we can make sure this fd must be fd instead of equiv class when we go here
planner/core/logical_plans.go
Outdated
} else { | ||
for k, v := range rightFD.HashCodeToUniqueID { | ||
if _, ok := fds.HashCodeToUniqueID[k]; ok { | ||
panic("shouldn't be here, children has same expr while registered not only once") |
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.
Please avoid panic
.
ok bool | ||
constantUniqueID int | ||
) | ||
if constantUniqueID, ok = fds.IsHashCodeRegistered(hashCode); !ok { |
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.
What would happen for the ok
case?
If the same constant appears in different operators but corresponds to different UniqueID
, will there be mistakes?
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.
The same constant will use the same hashcode, then use the same unique id here.
This is temp solution to fix it before we refactor the way we store the const.
planner/core/logical_plans.go
Outdated
result := expression.EvaluateExprWithNull(p.ctx, p.schema, x) | ||
con, ok := result.(*expression.Constant) | ||
if !ok || con.Value.IsNull() { | ||
// if x can be nullable when referred columns are null, the extended column can be nullable. | ||
nullable = true | ||
} | ||
if !nullable || determinants.SubsetOf(fds.NotNullCols) { |
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.
I think it's the same as isNullRejected
.
planner/core/logical_plans.go
Outdated
case *expression.ScalarFunction: | ||
scalarUniqueID, ok := fds.IsHashCodeRegistered(string(hack.String(x.HashCode(p.SCtx().GetSessionVars().StmtCtx)))) | ||
if !ok { | ||
panic("selected expr must have been registered, shouldn't be here") |
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.
Please avoid panic
.
planner/core/logical_plan_builder.go
Outdated
// 1: normal value can be multiple | ||
// 2: null value can be multiple | ||
// for this kind of lax to be strict, we need to make both the determinant and dependency not-null. | ||
fds.AddLaxFunctionalDependency(keyCols, allCols, false) |
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.
Could non-unique index become functional dependency?
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.
No
a b
1 2
1 3
2 2
There's an index on (a).
You can see that we cannot build either strict or lax functional dependency.
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.
make sense, we should remove this
planner/core/logical_plans.go
Outdated
fds.NotNullCols.UnionWith(rightFD.NotNullCols) | ||
if fds.HashCodeToUniqueID == nil { | ||
fds.HashCodeToUniqueID = rightFD.HashCodeToUniqueID | ||
} else { | ||
for k, v := range rightFD.HashCodeToUniqueID { | ||
if _, ok := fds.HashCodeToUniqueID[k]; ok { | ||
panic("shouldn't be here, children has same expr while registered not only once") | ||
} | ||
fds.HashCodeToUniqueID[k] = v | ||
} | ||
} | ||
for i, ok := rightFD.GroupByCols.Next(0); ok; i, ok = rightFD.GroupByCols.Next(i + 1) { | ||
fds.GroupByCols.Insert(i) | ||
} | ||
fds.HasAggBuilt = fds.HasAggBuilt || rightFD.HasAggBuilt |
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.
I think they should be put into MakeCartesianProduct
.
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.
MakeCartesianProduct
will be also used in outer join. So we cannot put it into it.
eqCondSlice := expression.ScalarFuncs2Exprs(p.EqualConditions) | ||
// some join eq conditions are stored in the OtherConditions. | ||
allConds := append(eqCondSlice, p.OtherConditions...) |
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.
Do we need to consider LeftConditions
and RightConditions
?
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.
We only need to consider that in outer join.
/merge |
This pull request has been accepted and is ready to merge. Commit hash: faa629c
|
@winoros: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 9c1d963
|
/merge |
@winoros: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: ref #29766
Problem Summary:
What is changed and how it works?
This pr adds the maintain of functional dependency for datasource, projection, selection, aggregation, inner join and semi join.
In next pr, we would add outer join and open the check.
Check List
Tests
Side effects
Documentation
Release note