-
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
executor: fix the behavior when index join meet prefix index #11081
Changes from 3 commits
7a24650
cf04a88
4801dec
8b03d99
865f1d7
613d92b
7b25ce6
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 |
---|---|---|
|
@@ -89,6 +89,8 @@ type innerCtx struct { | |
readerBuilder *dataReaderBuilder | ||
rowTypes []*types.FieldType | ||
keyCols []int | ||
colLens []int | ||
hasPrefixCol bool | ||
} | ||
|
||
type lookUpJoinTask struct { | ||
|
@@ -473,6 +475,10 @@ func (iw *innerWorker) handleTask(ctx context.Context, task *lookUpJoinTask) err | |
func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoinLookUpContent, error) { | ||
lookUpContents := make([]*indexJoinLookUpContent, 0, task.outerResult.NumRows()) | ||
keyBuf := make([]byte, 0, 64) | ||
keyTypes := make([]*types.FieldType, 0, len(iw.keyCols)) | ||
for _, pos := range iw.keyCols { | ||
keyTypes = append(keyTypes, iw.rowTypes[pos]) | ||
lzmhhh123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
for i := 0; i < task.outerResult.NumRows(); i++ { | ||
dLookUpKey, err := iw.constructDatumLookupKey(task, i) | ||
if err != nil { | ||
|
@@ -490,6 +496,16 @@ func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoi | |
} | ||
// Store the encoded lookup key in chunk, so we can use it to lookup the matched inners directly. | ||
task.encodedLookUpKeys.AppendBytes(0, keyBuf) | ||
if iw.hasPrefixCol { | ||
for i := range iw.outerCtx.keyCols { | ||
// If it's a prefix column. Try to fix it. | ||
if iw.colLens[i] != types.UnspecifiedLength { | ||
ranger.FixPrefixColDatum(&dLookUpKey[i], iw.colLens[i], keyTypes[i]) | ||
} | ||
} | ||
// dLookUpKey is sorted and deduplicated at sortAndDedupLookUpContents. | ||
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. Unnecessary comment? 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. Just to tell why we don't sort it here? |
||
// So we don't need to do it here. | ||
} | ||
lookUpContents = append(lookUpContents, &indexJoinLookUpContent{keys: dLookUpKey, row: task.outerResult.GetRow(i)}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,10 +263,10 @@ func buildColumnRange(accessConditions []expression.Expression, sc *stmtctx.Stat | |
} | ||
if colLen != types.UnspecifiedLength { | ||
for _, ran := range ranges { | ||
if fixRangeDatum(&ran.LowVal[0], colLen, tp) { | ||
if FixPrefixColDatum(&ran.LowVal[0], colLen, tp) { | ||
ran.LowExclude = false | ||
} | ||
if fixRangeDatum(&ran.HighVal[0], colLen, tp) { | ||
if FixPrefixColDatum(&ran.HighVal[0], colLen, tp) { | ||
ran.HighExclude = false | ||
} | ||
} | ||
|
@@ -425,17 +425,17 @@ func fixPrefixColRange(ranges []*Range, lengths []int, tp []*types.FieldType) bo | |
for _, ran := range ranges { | ||
lowTail := len(ran.LowVal) - 1 | ||
for i := 0; i < lowTail; i++ { | ||
fixRangeDatum(&ran.LowVal[i], lengths[i], tp[i]) | ||
FixPrefixColDatum(&ran.LowVal[i], lengths[i], tp[i]) | ||
} | ||
lowCut := fixRangeDatum(&ran.LowVal[lowTail], lengths[lowTail], tp[lowTail]) | ||
lowCut := FixPrefixColDatum(&ran.LowVal[lowTail], lengths[lowTail], tp[lowTail]) | ||
if lowCut { | ||
ran.LowExclude = false | ||
} | ||
highTail := len(ran.HighVal) - 1 | ||
for i := 0; i < highTail; i++ { | ||
fixRangeDatum(&ran.HighVal[i], lengths[i], tp[i]) | ||
FixPrefixColDatum(&ran.HighVal[i], lengths[i], tp[i]) | ||
} | ||
highCut := fixRangeDatum(&ran.HighVal[highTail], lengths[highTail], tp[highTail]) | ||
highCut := FixPrefixColDatum(&ran.HighVal[highTail], lengths[highTail], tp[highTail]) | ||
if highCut { | ||
ran.HighExclude = false | ||
} | ||
|
@@ -444,9 +444,9 @@ func fixPrefixColRange(ranges []*Range, lengths []int, tp []*types.FieldType) bo | |
return hasCut | ||
} | ||
|
||
func fixRangeDatum(v *types.Datum, length int, tp *types.FieldType) bool { | ||
// If this column is prefix and the prefix length is smaller than the range, cut it. | ||
// In case of UTF8, prefix should be cut by characters rather than bytes | ||
// FixPrefixColDatum cuts the datum according to the prefix length. | ||
// If it's UTF8 encoded, we will cut it by characters rather than bytes. | ||
func FixPrefixColDatum(v *types.Datum, length int, tp *types.FieldType) bool { | ||
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. how about |
||
if v.Kind() == types.KindString || v.Kind() == types.KindBytes { | ||
colCharset := tp.Charset | ||
colValue := v.GetBytes() | ||
|
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.
move line#478~481 to line #500 ?
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.
line500 is in a for loop.
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.
before
for loop
and afterif
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.
The
if
branch is already in a for loop