-
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,executor: fix 'select ...(join on partition table) for update' panic #21148
planner,executor: fix 'select ...(join on partition table) for update' panic #21148
Conversation
…' panic Let the table reader return an extra column with partition ID, so the SelectLockExec can use that partition ID to construct the lock key.
PTAL @SunRunAway @eurekaka |
Adjusted according to the advice from @eurekaka
Some extra information is still necessary for SelectLock to know the mapping from table ID to the partition column index. |
/run-check_dev_2 |
7156c1f
to
e1bbb74
Compare
I have reverted the code to the previous implementation. For example, in the physical optimizing phase, if there is only one KV entry in the range, DataSource will be converted to PointGet, but the schema is not correct, the extra PID column is not pruned. The current implementation only adds the partition ID column when there is a SelectLock on the partitioned table, so the change is minimal and no other parts are affected. PTAL @eurekaka |
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
for i := 0; i < len(v.ExtraPIDInfo.Columns); i++ { | ||
col := v.ExtraPIDInfo.Columns[i] | ||
tblID := v.ExtraPIDInfo.TblIDs[i] | ||
offset := schema.ColumnIndex(col) |
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.
Check the column.ID == model.ExtraPidColID
is better
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.
Check the column to be ExtraPidColID
can get the column index in the schema, but can't build the mapping of
table ID => partition column index in the schema
Here we take each partition column (v.ExtraPIDInfo.Columns[i]) and find its index in the schema (offset), to build the
mapping tblID(v.ExtraPIDInfo.TblIDs[i])
=> offset
This pull request has been accepted and is ready to merge. Commit hash: 98872f4
|
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #25501 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-5.1 in PR #25502 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-5.0 in PR #25845 |
This PR is terrible... it's a nightmare... |
What problem does this PR solve?
Issue Number: close #20028
Problem Summary:
'select ... for update' need the table ID to construct the lock key.
When this SQL works on a partitioned table, the table ID should be partition ID.
So how to get that partition ID?
In http://github.com/pingcap/tidb/pull/14921 I try to avoid column pruning of the partition columns,
so we can get the partition column data, and then use it to calculate the partition to get the ID.
That fix works on a single table, but not the joining of tables.
What is changed and how it works?
What's Changed:
In the logical plan phase, if
buildSelectLock
find itself works on partitioned tables,change the schema add an extra partition ID column to the DataSource.
Some tiny changes in the column pruning step to get the correct schema.
In the TableReader executor, fill the extra partition ID column in the chunk row.
In the SelectLockExec, use the partition ID from the chunk row, to construct the correct lock key.
How it Works:
Let the table reader return an extra column with partition ID, so the
SelectLockExec can use that partition ID to construct the lock key.
Related changes
Check List
Tests
Release note