-
Notifications
You must be signed in to change notification settings - Fork 6k
*: let TempIndex support encode/decode partitionID flag #57017
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
Changes from 5 commits
8478f52
290b723
1a04ad3
883d0cb
82aae36
dae202a
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 |
---|---|---|
|
@@ -1307,16 +1307,32 @@ func (v TempIndexValue) FilterOverwritten() TempIndexValue { | |
// A temp index value element is encoded as one of: | ||
// - [flag 1 byte][value_length 2 bytes ] [value value_len bytes] [key_version 1 byte] {distinct normal} | ||
// - [flag 1 byte][value value_len bytes] [key_version 1 byte] {non-distinct normal} | ||
// - [flag 1 byte][handle_length 2 bytes] [handle handle_len bytes] [key_version 1 byte] {distinct deleted} | ||
// - [flag 1 byte][handle_length 2 bytes] [handle handle_len bytes] [partitionIdFlag 1 byte] [partitionID 8 bytes] [key_version 1 byte] {distinct deleted} | ||
// - [flag 1 byte] [key_version 1 byte] {non-distinct deleted} | ||
type TempIndexValueElem struct { | ||
Value []byte | ||
Handle kv.Handle | ||
KeyVer byte | ||
Delete bool | ||
Distinct bool | ||
|
||
Defined2014 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Global means it's a global Index, for partitioned tables. Only for `distinct` + `deleted` scenario right now. | ||
Defined2014 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Global bool | ||
Defined2014 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const ( | ||
// TempIndexKeyTypeNone means the key is not a temporary index key. | ||
TempIndexKeyTypeNone byte = 0 | ||
// TempIndexKeyTypeDelete indicates this value is written in the delete-only stage. | ||
TempIndexKeyTypeDelete byte = 'd' | ||
// TempIndexKeyTypeBackfill indicates this value is written in the backfill stage. | ||
TempIndexKeyTypeBackfill byte = 'b' | ||
// TempIndexKeyTypeMerge indicates this value is written in the merge stage. | ||
TempIndexKeyTypeMerge byte = 'm' | ||
// TempIndexKeyTypePartitionIDFlag indicates the following value is partition id. | ||
TempIndexKeyTypePartitionIDFlag byte = 'p' | ||
) | ||
|
||
// Encode encodes the temp index value. | ||
func (v *TempIndexValueElem) Encode(buf []byte) []byte { | ||
if v.Delete { | ||
|
@@ -1331,13 +1347,21 @@ func (v *TempIndexValueElem) Encode(buf []byte) []byte { | |
hEncoded = handle.Encoded() | ||
hLen = uint16(len(hEncoded)) | ||
} | ||
// flag + handle length + handle + temp key version | ||
// flag + handle length + handle + [partition id] + temp key version | ||
if buf == nil { | ||
buf = make([]byte, 0, hLen+4) | ||
l := hLen + 4 | ||
if v.Global { | ||
l += 9 | ||
} | ||
buf = make([]byte, 0, l) | ||
} | ||
buf = append(buf, byte(TempIndexValueFlagDeleted)) | ||
buf = append(buf, byte(hLen>>8), byte(hLen)) | ||
buf = append(buf, hEncoded...) | ||
if v.Global { | ||
buf = append(buf, TempIndexKeyTypePartitionIDFlag) | ||
buf = append(buf, codec.EncodeInt(nil, v.Handle.(kv.PartitionHandle).PartitionID)...) | ||
} | ||
buf = append(buf, v.KeyVer) | ||
return buf | ||
} | ||
|
@@ -1415,6 +1439,16 @@ func (v *TempIndexValueElem) DecodeOne(b []byte) (remain []byte, err error) { | |
v.Handle, _ = kv.NewCommonHandle(b[:hLen]) | ||
} | ||
b = b[hLen:] | ||
if b[0] == TempIndexKeyTypePartitionIDFlag { | ||
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 this only needed here, and not also in 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. Yes, only delete will include handle. https://github.com/pingcap/tidb/pull/57017/files#diff-d38a794eb5c0ced0fe2e07bc0af6bd8624e360f4c5055b6c7075d62afac48569R1310 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. |
||
v.Global = true | ||
var pid int64 | ||
_, pid, err = codec.DecodeInt(b[1:9]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
v.Handle = kv.NewPartitionHandle(pid, v.Handle) | ||
b = b[9:] | ||
} | ||
v.KeyVer = b[0] | ||
b = b[1:] | ||
v.Distinct = true | ||
|
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.
Curious question: In this function is
m.ints
andm.strs
empty ifm.partitionInts
andm.partitionStrs
is used and vice versa? Or can both pair of maps be used at the same time?Uh oh!
There was an error while loading. Please reload this page.
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.
Could both used.