-
Notifications
You must be signed in to change notification settings - Fork 5.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
planner, executor: fix index merge partial table scan schema #23936
Conversation
/hold |
087f198
to
39974c1
Compare
_tidb_rowid
to DataSource
schema in index merge
39974c1
to
d131acb
Compare
_tidb_rowid
to DataSource
schema in index merge
/unhold |
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.
/lgtm
@eurekaka: In response to this:
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. |
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.
/lgtm
/lgtm |
[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 writing |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 42e3493
|
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-5.0 in PR #24155 |
What problem does this PR solve?
Issue Number: close #23919
Problem Summary:
ERROR 1105 (HY000): runtime error: index out of range [2] with length 2
The explain result:
SortExec.Next()
only requires 2 columns(a
andb
), but the row fetched from the underlyingUnionExec
has 3(a
,b
and_tidb_rowid
). This causeChunk.AppendPartialRow
panic because the slice out-of-range error.The request chunk for
UnionExec.Next
should have only 2 columns, butreq.SwapColumns(result.chk)
change it into a 3-columns chunk. This chunk comes fromIndexMergeReaderExecutor
, which has a 3-columns schema.IndexMergeReaderExecutor
inherits the schema fromPhysicalIndexMergeReader
, which inherits from thePhysicalTableScan
built bybuildIndexMergeTableScan
:tidb/planner/core/find_best_task.go
Lines 903 to 914 in 008b91b
It appends the
_tidb_rowid
to the schema ofDataSource
to helpHandleCols
resolve its indices.The
HandleCols
is used to fetch handles in bothTableRangeScan
andIndexRangeScan
.TableRangeScan
, the current schema is fromDataSource
plus additional common handle columns. This is unresonable because only the handle columns are needed.IndexRangeScan
, the current schema is always indexed columns plus full common handle columns.ResolveIndices
is useless inIndexRangeScan
because theexpression.Column.Index
is never used.What is changed and how it works?
How it Works:
This PR makes the schema of
IndexMerge
consistent with the upper operator, by avoid changingDataSource
schema directly. It also fixes the issue in #23933 (review).What is changed:
TableRangeScan
(as a child ofIndexMerge
operator) to the one that only contains handle columns.HandleCols
inIndexMergeReaderExecutor
against the schema that only contains the handle columns.clustered index/_tidb_rowid/PkIsHandle
for index merge.Related changes
NA
Check List
Tests
Side effects
NA
Release note