-
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
*: fix 'select for update' on partitioned table again #30732
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package executor | |
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"math" | ||
"sort" | ||
"strconv" | ||
|
@@ -631,10 +632,9 @@ func (b *executorBuilder) buildSelectLock(v *plannercore.PhysicalLock) Executor | |
return src | ||
} | ||
e := &SelectLockExec{ | ||
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ID(), src), | ||
Lock: v.Lock, | ||
tblID2Handle: v.TblID2Handle, | ||
partitionedTable: v.PartitionedTable, | ||
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ID(), src), | ||
Lock: v.Lock, | ||
tblID2Handle: v.TblID2Handle, | ||
} | ||
|
||
// filter out temporary tables because they do not store any record in tikv and should not write any lock | ||
|
@@ -650,14 +650,38 @@ func (b *executorBuilder) buildSelectLock(v *plannercore.PhysicalLock) Executor | |
} | ||
} | ||
|
||
if len(e.partitionedTable) > 0 { | ||
schema := v.Schema() | ||
e.tblID2PIDColumnIndex = make(map[int64]int) | ||
for i := 0; i < len(v.ExtraPIDInfo.Columns); i++ { | ||
col := v.ExtraPIDInfo.Columns[i] | ||
tblID := v.ExtraPIDInfo.TblIDs[i] | ||
offset := schema.ColumnIndex(col) | ||
e.tblID2PIDColumnIndex[tblID] = offset | ||
if len(v.PartitionedTable) > 0 { | ||
e.partitionedTable = make(map[int64]table.PartitionedTable) | ||
e.tblID2PtColsOffsets = make(map[int64][]int) | ||
|
||
for _, pt := range v.PartitionedTable { | ||
tblInfo := pt.Meta() | ||
e.partitionedTable[tblInfo.ID] = pt | ||
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. Is the 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.
|
||
dbInfo, ok := is.SchemaByTable(tblInfo) | ||
if !ok { | ||
b.err = errors.Trace(errors.Errorf("Cannot get schema info for table %s", tblInfo.Name.O)) | ||
return nil | ||
} | ||
|
||
cols := pt.VisibleCols() | ||
offsets := make([]int, 0, len(cols)) | ||
for _, colInfo := range cols { | ||
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. Why create this double loop for each partition? |
||
colName := fmt.Sprintf("%s.%s.%s", dbInfo.Name.L, tblInfo.Name.L, colInfo.Name.L) | ||
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. Will there be some colume names not in this format like |
||
|
||
match := false | ||
for i, col := range e.schema.Columns { | ||
if col.OrigName == colName { | ||
match = true | ||
offsets = append(offsets, i) | ||
break | ||
} | ||
} | ||
if !match { | ||
b.err = errors.Trace(errors.Errorf("Table %s column %s cannot find data with select result", tblInfo.Name.O, colInfo.Name.L)) | ||
return nil | ||
} | ||
} | ||
e.tblID2PtColsOffsets[tblInfo.ID] = offsets | ||
} | ||
} | ||
return e | ||
|
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.
Do we really need this? Is not the
e.tblID2Handle
enough?