forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 1
refactor order-by fd check #14
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
Open
AilinKid
wants to merge
13
commits into
winoros:functional-dependency
Choose a base branch
from
AilinKid:fix-order-by-fd
base: functional-dependency
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2baed3e
fix order by fd check
AilinKid b7fc20d
make test pass
AilinKid 2e1c49f
fix orm django agg test case
AilinKid e2f712f
fix order by should see new p.schema after order item is built
AilinKid 20e1a23
fix corrleated column in order by clause can't be name-resolved
AilinKid 13da49a
move order by check logical to buildOrderBy
AilinKid 6fd8035
fix order by for skipping extract correlated col
61bc37a
add addFrom commnet
19d47b0
.
34ee6d5
add test
2d18cc8
fix-order-by-fd2
AilinKid a03a853
fix the refine test
AilinKid b3b600e
Update planner/core/logical_plan_builder.go
AilinKid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,154 @@ package funcdep | |
| // https://cs.uwaterloo.ca/research/tr/2000/11/CS-2000-11.thesis.pdf | ||
|
|
||
| // TODO: Add the RFC design. | ||
|
|
||
| // NOTE 1. | ||
| // when handling Lax FD, we don't care the null value in the dependency, which means | ||
| // as long as null-attribute coverage of the determinant can make a Lax FD as strict one. | ||
|
|
||
| // The definition of "lax" used in the paper differs from the definition used by this | ||
| // library. For a lax dependency A~~>B, the paper allows this set of rows: | ||
| // | ||
| // a b | ||
| // ------- | ||
| // 1 1 | ||
| // 1 NULL | ||
| // | ||
| // This alternate definition is briefly covered in section 2.5.3.2 of the paper (see definition | ||
| // 2.19). The reason for this change is to allow a lax dependency to be upgraded to a strict | ||
| // dependency more readily, needing only the determinant columns to be not-null rather than | ||
| // both determinant and dependant columns. | ||
| // | ||
| // This is on the condition that, for definite values of determinant of a Lax FD, it won't | ||
| // have two same definite dependant value. That's true, because there is no way can derive | ||
| // to this kind of FD. | ||
| // | ||
| // Even in our implementation of outer join, the only way to produce duplicate definite | ||
| // determinant is the join predicate. But for now, we only maintain the equivalence and | ||
| // some strict FD of it. | ||
| // | ||
| // t(a,b) left join t1(c,d,e) on t.a = t1.c and b=1 | ||
| // a b | c d e | ||
| // ------+---------------- | ||
| // 1 1 | 1 NULL 1 | ||
| // 1 2 | NULL NULL NULL | ||
| // 2 1 | NULL NULL NULL | ||
| // | ||
| // Actually it's possible, the lax FD {a} -> {c} can be derived but not that useful. we only | ||
| // maintain the {c} ~> {a} for existence after outer join. Besides, there two Cond-FD should | ||
| // be preserved waiting for be visible again once with the null-reject on the condition of | ||
| // null constraint columns. (see below) | ||
| // | ||
| // NOTE 2. | ||
| // When handle outer join, it won't produce lax FD with duplicate definite determinant values and | ||
| // different dependency values. | ||
| // | ||
| // In implementation,we come across some lax FD dependent on null-reject of some other cols. For | ||
| // example. | ||
| // t(a,b) left join t1(c,d,e) on t.a = t1.c and b=1 | ||
| // a b | c d e | ||
| // ------+---------------- | ||
| // 1 1 | 1 NULL 1 | ||
| // 1 2 | NULL NULL NULL | ||
| // 2 1 | NULL NULL NULL | ||
| // | ||
| // here constant FD {} -> {b} won't be existed after the outer join is done. Notice null-constraint | ||
| // {c,d,e} -| {c,d,e}, this FD should be preserved and will be visible again when some null-reject | ||
| // predicate take effect on the null-constraint cols. | ||
| // | ||
| // It's same for strict equivalence {t.a} = {t1.c}. Notice there are no lax equivalence here, because | ||
| // left side couldn't be guaranteed to be definite or null. like a=2 here. Let's collect all of this | ||
| // on-condition FD down, correspondent with a null-constraints column set, name it as Cond-FD. | ||
| // | ||
| // lax equivalencies are theoretically possible, but it won't be constructed from an outer join unless | ||
| // t already has a constant FD in column `a` here before outer join take a run. So the lax equivalence | ||
| // has some pre-conditions as you see, and it couldn't cover the case shown above. Let us do it like a | ||
| // Cond-FD does. | ||
| // | ||
| // The FD constructed from the join predicate should be considered as Cond-FD. Here like equivalence of | ||
| // {a} == {c} and constant FD {b} = 1 (if the join condition is e=1, it's here too). We can say that for | ||
| // every matched row, this FDs is valid, while for the other rows, the inner side are supplied of null | ||
| // rows. So this FDs are stored as ncEdges with nc condition of all inner table cols. | ||
| // | ||
| // We introduced invisible FD with null-constraint column to solve the problem above named as Cond-FD. | ||
| // For multi embedded left join, we take the following case as an example. | ||
| // a,b c,d,e | ||
| // -----------+----------- | ||
| // 1 2 | 1 1 1 | ||
| // 2 2 | | ||
| // -----------+----------- | ||
| // | ||
| // left join on (a=c) res: | ||
| // a b c e e | ||
| // ------------------------- | ||
| // 1 2 1 1 1 | ||
| // 2 2 +- null null null -+ | ||
| // | | | ||
| // +-------------------+ | ||
| // \ | ||
| // \ | ||
| // the Cond-FD are < a=c with {c,d,e} > the latter is as null constraint cols | ||
| // | ||
| // e,f | ||
| // ----------------------- | ||
| // 1 2 | ||
| // 2 2 | ||
| // 3 3 | ||
| // ----------------------- | ||
| // | ||
| // left join on (e=a) res: | ||
| // e f a b c d e | ||
| // ----------------------------------- | ||
| // 1 2 1 2 1 1 1 | ||
| // 2 2 2 2 +- null null null --+---------------> Cond-FD are <a=c with {c,d,e}> still exists. | ||
| // 3 3 +-null null | null null null |---+ | ||
| // | +-------------------+ | | ||
| // +-----------------------------------+-----------> New Cond-FD are <e=a with {a,b,c,d,e}> occurs. | ||
| // | ||
| // | ||
| // the old Cond-FD with null constraint columns set {c,d,e} is preserved cause new append cols are all null too. | ||
| // the new Cond-FD with null constraint columns set {a,b,c,d,e} are also meaningful, even if the null-reject column | ||
| // is one of {c,d,e} which may reduce one of the matched row out of the result, the equivalence {a}={e} still exist. | ||
| // | ||
| // Provide that the result of the first left join is like: | ||
| // left join on (a=c) res: | ||
| // a b c e e | ||
| // --------------------------- | ||
| // 1 2 1 1 1 | ||
| // null 2 null null null | ||
| // | ||
| // THEN: left join on (e=a) res: | ||
| // e f a b c d e | ||
| // --------------------------------- | ||
| // 1 2 1 2 1 1 1 | ||
| // 2 2 null null null null null | ||
| // 3 3 3 3 null null null | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L134 should be |
||
| // | ||
| // Even like that, the case of old Cond-FD and new Cond-FD are existed too. Seems the null-constraint column set of | ||
| // old Cond-FD {c,d,e} can be expanded as {a,b,c,d,e} visually, but we couldn't derive the inference of the join predicate | ||
| // (e=a). The null-reject of column `a` couldn't bring the visibility to the old Cond-FD theoretically, it just happened | ||
| // to refuse that row with a null value in column a. | ||
| // | ||
| // Think about adding one more row in first left join result. | ||
| // | ||
| // left join on (a=c) res: | ||
| // a b c e e | ||
| // --------------------------- | ||
| // 1 2 1 1 1 | ||
| // null 2 null null null | ||
| // 3 3 null null null | ||
| // | ||
| // THEN: left join on (e=a) res: | ||
| // e f a b c d e | ||
| // --------------------------------- | ||
| // 1 2 1 2 1 1 1 | ||
| // 2 2 null null null null null | ||
| // 3 3 3 3 null null null | ||
| // | ||
| // Conclusion: | ||
| // As you see that's right we couldn't derive the inference of the join predicate (e=a) to expand old Cond-FD's nc | ||
| // {c,d,e} as {a,b,c,d,e}. So the rule for Cond-FD is quite simple, just keep the old ncEdge from right, appending | ||
| // the new ncEdges in current left join. | ||
| // | ||
| // If the first left join result is in the outer side of the second left join, just keep the ncEdge from left as well, | ||
| // appending the new ncEdges in current left join. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.