Skip to content
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: fix CTE bug when MergeJoin is used #25514

Merged
merged 3 commits into from
Jul 27, 2021

Conversation

guo-shaoge
Copy link
Collaborator

Signed-off-by: guo-shaoge shaoge1994@163.com

What problem does this PR solve?

Issue Number: close #25474

Problem Summary: When use MERGE JOIN to join a CTE table, planner give errors

mysql>     with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from t1 where c1 < 3) select /*+ MERGE_JOIN(dt1, dt2) */ * from cte1 dt1 left join t1 dt2 on dt1.c1 = dt2.c1 order by dt1.c1, dt2.c1;
ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query

What is changed and how it works?

What's Changed: Change logic in LogicalCTE.findBestTask, when prop requires sort item, we add a sort operator explicitly.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Integration test

Side effects: no

  • Performance regression
    • Consumes more CPU
    • Consumes more MEM
  • Breaking backward compatibility

Release note

  • planner: fix CTE bug when MergeJoin is used

@guo-shaoge guo-shaoge requested a review from a team as a code owner June 17, 2021 06:43
@guo-shaoge guo-shaoge requested review from XuHuaiyu and removed request for a team June 17, 2021 06:43
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 17, 2021
@guo-shaoge guo-shaoge requested review from wjhuang2016 and removed request for XuHuaiyu June 17, 2021 06:43
@guo-shaoge
Copy link
Collaborator Author

/label needs-cherry-pick-to-5.1

@ti-chi-bot
Copy link
Member

@guo-shaoge: The label(s) needs-cherry-pick-to-5.1 cannot be applied. These labels are supported: CHANGELOG, challenge-program, compatibility-breaker, contribution, correctness, first-time-contributor, good-first-issue, hacktoberfest, high-performance, hptc, need-more-info, needs-cherry-pick-3.0, needs-cherry-pick-3.1, needs-cherry-pick-4.0, needs-cherry-pick-5.0, needs-cherry-pick-5.1, proposal, release-note, require-LGT3, security, tools.

In response to this:

/label needs-cherry-pick-to-5.1

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.

@guo-shaoge
Copy link
Collaborator Author

/label needs-cherry-pick-5.1

@zhouqiang-cl
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@zhouqiang-cl: /merge in this pull request requires 2 approval(s).

In response to this:

/merge

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.

@zhouqiang-cl
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@zhouqiang-cl: /merge in this pull request requires 2 approval(s).

In response to this:

/merge

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.

@guo-shaoge guo-shaoge requested a review from a team as a code owner June 17, 2021 08:27
@guo-shaoge guo-shaoge requested review from XuHuaiyu and removed request for a team and XuHuaiyu June 17, 2021 08:27
@github-actions github-actions bot added the sig/execution SIG execution label Jun 17, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

3 similar comments
@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

wjhuang2016
wjhuang2016 previously approved these changes Jun 17, 2021
planner/core/find_best_task.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 17, 2021
@pingcap pingcap deleted a comment from ti-chi-bot Jun 17, 2021
@guo-shaoge guo-shaoge requested review from a team and qw4990 and removed request for a team June 22, 2021 02:11
@guo-shaoge
Copy link
Collaborator Author

@wjhuang2016 ptal~

@guo-shaoge
Copy link
Collaborator Author

/run-integration-common-test
/run-common-test
/run-integration-copr-test

@guo-shaoge
Copy link
Collaborator Author

/run-integration-common-test
/run-common-test

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 21, 2021
id estRows task access object operator info
MergeJoin_24 10000.00 root inner join, left key:test.tpk.c1, right key:test.tpk.c1
├─Sort_22(Build) 8000.00 root test.tpk.c1
│ └─Selection_20 8000.00 root not(isnull(test.tpk.c1))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra sort operator, because tpk.c1 is orded.

@guo-shaoge
Copy link
Collaborator Author

@wjhuang2016 ptal

if err != nil {
return
}
if !prop.IsEmpty() && prop.CanAddEnforcer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prop.CanAddEnforcer must be true here.

return invalidTask, 1, nil
}
if p.cte.cteTask != nil {
t = p.cte.cteTask
defer func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We better add some tests for the case that different prop on CTE

Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge
Copy link
Collaborator Author

/run-check_dev_2

@guo-shaoge
Copy link
Collaborator Author

@wjhuang2016 ptal

1 1
2 2
3 3
// No Sort on CTE. Because we have order by in CTE definition.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need fix

Signed-off-by: guo-shaoge <shaoge1994@163.com>
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • wjhuang2016

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 27, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-check_dev_2

@wjhuang2016
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 0885f07

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 27, 2021
@ti-chi-bot ti-chi-bot merged commit 57d704b into pingcap:master Jul 27, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jul 27, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.1 in PR #26658

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.1 sig/execution SIG execution size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Got error when use merge_join hint in CTE
6 participants