-
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
*: fix insert on duplicate
and replace into
with global index
#53717
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 |
---|---|---|
|
@@ -1178,7 +1178,7 @@ func (e *InsertValues) handleDuplicateKey(ctx context.Context, txn kv.Transactio | |
} | ||
return true, nil | ||
} | ||
_, handle, err := tables.FetchDuplicatedHandle(ctx, uk.newKey, true, txn, e.Table.Meta().ID, uk.commonHandle) | ||
_, handle, err := tables.FetchDuplicatedHandle(ctx, uk.newKey, true, txn, e.Table.Meta().ID) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
@@ -1373,7 +1373,11 @@ func (e *InsertValues) removeRow( | |
return true, nil | ||
} | ||
|
||
err = r.t.RemoveRecord(e.Ctx().GetTableCtx(), handle, oldRow) | ||
if ph, ok := handle.(kv.PartitionHandle); ok { | ||
err = e.Table.(table.PartitionedTable).GetPartition(ph.PartitionID).RemoveRecord(e.Ctx().GetTableCtx(), ph.Handle, oldRow) | ||
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. Also Note for future reference. |
||
} else { | ||
err = r.t.RemoveRecord(e.Ctx().GetTableCtx(), handle, oldRow) | ||
} | ||
if err != nil { | ||
return false, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,9 @@ func CutRowKeyPrefix(key kv.Key) []byte { | |
// EncodeRecordKey encodes the recordPrefix, row handle into a kv.Key. | ||
func EncodeRecordKey(recordPrefix kv.Key, h kv.Handle) kv.Key { | ||
buf := make([]byte, 0, len(recordPrefix)+h.Len()) | ||
if ph, ok := h.(kv.PartitionHandle); ok { | ||
recordPrefix = GenTableRecordPrefix(ph.PartitionID) | ||
} | ||
buf = append(buf, recordPrefix...) | ||
buf = append(buf, h.Encoded()...) | ||
return buf | ||
|
@@ -960,7 +963,7 @@ func DecodeIndexHandle(key, value []byte, colsLen int) (kv.Handle, error) { | |
if len(b) > 0 { | ||
return decodeHandleInIndexKey(b) | ||
} else if len(value) >= 8 { | ||
return decodeHandleInIndexValue(value) | ||
return DecodeHandleInIndexValue(value) | ||
} | ||
// Should never execute to here. | ||
return nil, errors.Errorf("no handle in index key: %v, value: %v", key, value) | ||
|
@@ -977,7 +980,11 @@ func decodeHandleInIndexKey(keySuffix []byte) (kv.Handle, error) { | |
return kv.NewCommonHandle(keySuffix) | ||
} | ||
|
||
func decodeHandleInIndexValue(value []byte) (handle kv.Handle, err error) { | ||
// DecodeHandleInIndexValue decodes handle in unqiue index value. | ||
func DecodeHandleInIndexValue(value []byte) (handle kv.Handle, err error) { | ||
if len(value) <= MaxOldEncodeValueLen { | ||
return decodeIntHandleInIndexValue(value), nil | ||
} | ||
Comment on lines
+985
to
+987
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. Could we remove these codes that look like they will be processed on line988? 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. This speeds up the function for simplest int handles(like 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. The performance difference is 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. Got it. |
||
seg := SplitIndexValue(value) | ||
if len(seg.IntHandle) != 0 { | ||
handle = decodeIntHandleInIndexValue(seg.IntHandle) | ||
|
@@ -1676,35 +1683,6 @@ func encodeCommonHandle(idxVal []byte, h kv.Handle) []byte { | |
return idxVal | ||
} | ||
|
||
// DecodeHandleInUniqueIndexValue decodes handle in data. | ||
func DecodeHandleInUniqueIndexValue(data []byte, isCommonHandle bool) (kv.Handle, error) { | ||
if !isCommonHandle { | ||
dLen := len(data) | ||
if dLen <= MaxOldEncodeValueLen { | ||
return kv.IntHandle(int64(binary.BigEndian.Uint64(data))), nil | ||
} | ||
return kv.IntHandle(int64(binary.BigEndian.Uint64(data[dLen-int(data[0]):]))), nil | ||
} | ||
if getIndexVersion(data) == 1 { | ||
seg := splitIndexValueForClusteredIndexVersion1(data) | ||
h, err := kv.NewCommonHandle(seg.CommonHandle) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return h, nil | ||
} | ||
|
||
tailLen := int(data[0]) | ||
data = data[:len(data)-tailLen] | ||
handleLen := uint16(data[2])<<8 + uint16(data[3]) | ||
handleEndOff := 4 + handleLen | ||
h, err := kv.NewCommonHandle(data[4:handleEndOff]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return h, nil | ||
} | ||
|
||
func encodePartitionID(idxVal []byte, partitionID int64) []byte { | ||
idxVal = append(idxVal, PartitionIDFlag) | ||
idxVal = codec.EncodeInt(idxVal, partitionID) | ||
|
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.
(Note for future reference)
Will this work with partitions? Is e.table the partition if non-global index, and the logical table if global index?
=> EncodeRecordKey now adds the proper PhysicalTableID (partition id) if partitioned handle.