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

executor, planner: support indexMerge limit embeded with non partition table #42811

Merged
merged 8 commits into from
Apr 14, 2023

Conversation

Defined2014
Copy link
Contributor

@Defined2014 Defined2014 commented Apr 4, 2023

What problem does this PR solve?

Issue Number: ref #41028

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@Defined2014 Defined2014 added the needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. label Apr 4, 2023
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 4, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • guo-shaoge
  • winoros

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 do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 4, 2023
@ti-chi-bot ti-chi-bot removed do-not-merge/needs-linked-issue needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 7, 2023
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. label Apr 10, 2023
@Defined2014 Defined2014 removed needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Apr 11, 2023
@Defined2014 Defined2014 changed the title [WIP] executor, planner: support mergeSort for indexMerge executor, planner: support mergeSort for indexMerge Apr 11, 2023
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 11, 2023
@Defined2014 Defined2014 changed the title executor, planner: support mergeSort for indexMerge executor, planner: support push down limit into indexMerge for non partition table Apr 11, 2023
@Defined2014 Defined2014 changed the title executor, planner: support push down limit into indexMerge for non partition table executor, planner: support indexMerge limit embeded with non partition table Apr 11, 2023
@Defined2014
Copy link
Contributor Author

/retest

1 similar comment
@Defined2014
Copy link
Contributor Author

/retest


// pruneTableWorkerTaskIdxRows prune idxRows and only keep columns that will be used in byItems.
func (w *indexMergeProcessWorker) pruneTableWorkerTaskIdxRows(task *indexMergeTableTask) {
if plan, ok := w.indexMerge.partialPlans[task.partialPlanID][0].(*plannercore.PhysicalTableScan); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the bottom of the partial plan is IndexScan?

Copy link
Contributor Author

@Defined2014 Defined2014 Apr 12, 2023

Choose a reason for hiding this comment

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

The IndexScan no need prune retChk. Columns required by byItems are always first.

if plan, ok := w.indexMerge.partialPlans[task.partialPlanID][0].(*plannercore.PhysicalTableScan); ok {
prune := make([]int, 0, len(w.indexMerge.byItems))
for _, item := range plan.ByItems {
c, _ := item.Expr.(*expression.Column)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about order by an expression like col + 1?

Copy link
Contributor Author

@Defined2014 Defined2014 Apr 12, 2023

Choose a reason for hiding this comment

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

It's not support yet. The planner will not generate a such plan.

Copy link
Member

Choose a reason for hiding this comment

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

order by col+1 will be optimized to order by col.
order by f(col) or order by f(col1, col2) are clearly that they cannot use the order property of the index.

@Defined2014 Defined2014 reopened this Apr 12, 2023
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 13, 2023
if plan, ok := w.indexMerge.partialPlans[task.partialPlanID][0].(*plannercore.PhysicalTableScan); ok {
prune := make([]int, 0, len(w.indexMerge.byItems))
for _, item := range plan.ByItems {
c, _ := item.Expr.(*expression.Column)
Copy link
Member

Choose a reason for hiding this comment

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

The item.Expr.(*expression.Column).Index is the same thing as the i in for i, col := range plan.Schema().Columns.
You can use the Index directly.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the ByItems are shared between partial scans. We cannot use the Index. But i think we can use Schema.ColumnIndex or Schema.Contains to find the column by unique id, no need to use ID?

Copy link
Contributor Author

@Defined2014 Defined2014 Apr 14, 2023

Choose a reason for hiding this comment

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

Updated.
It confused me about ID and UniqueID in expression.Column. I found we use ID to compare with model.ColumnInfo, and use UniqueID to compare with expression.Column. @winoros

Copy link
Member

Choose a reason for hiding this comment

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

Yes, ID is the meta data of model.ColumnInfo, created by DDL. So ID is a table-level meta data.
UniqueID is generated during planning. It's unique at the SQL level.
We often use UniqueID to check the equivalence of the expression.Column. Use ID to know which ColumnInfo it represents.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 14, 2023
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 14, 2023
@Defined2014
Copy link
Contributor Author

/retest

1 similar comment
@Defined2014
Copy link
Contributor Author

/retest

@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 Apr 14, 2023
@Defined2014
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: ea995a9

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 14, 2023
@Defined2014
Copy link
Contributor Author

/retest

1 similar comment
@Defined2014
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot merged commit 2d0564c into pingcap:master Apr 14, 2023
@Defined2014 Defined2014 deleted the indexMerge branch April 14, 2023 07:29
@ti-chi-bot
Copy link
Member

@Defined2014: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/unit-test ea995a9 link true /test unit-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. 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.

4 participants