Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Jul 12, 2019
1 parent 4801dec commit 8b03d99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
6 changes: 1 addition & 5 deletions executor/index_lookup_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,6 @@ 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])
}
for i := 0; i < task.outerResult.NumRows(); i++ {
dLookUpKey, err := iw.constructDatumLookupKey(task, i)
if err != nil {
Expand All @@ -500,7 +496,7 @@ func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoi
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])
ranger.CutDatumByPrefixLen(&dLookUpKey[i], iw.colLens[i], iw.rowTypes[iw.keyCols[i]])
}
}
// dLookUpKey is sorted and deduplicated at sortAndDedupLookUpContents.
Expand Down
1 change: 0 additions & 1 deletion executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func (s *testSuite2) TestIssue11061(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(c varchar(30), index ix_c(c(10)))")
tk.MustExec("create table t2(d varchar(10))")
tk.MustExec("insert into t1 (c) values('7_chars'), ('13_characters')")
tk.MustExec("insert into t2 (d) values('13'), ('13'), ('7'), ('7')")
tk.MustQuery("SELECT /*+ TIDB_INLJ(t1) */ SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1)").Check(testkit.Rows("20"))
Expand Down
16 changes: 8 additions & 8 deletions util/ranger/ranger.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ func buildColumnRange(accessConditions []expression.Expression, sc *stmtctx.Stat
}
if colLen != types.UnspecifiedLength {
for _, ran := range ranges {
if FixPrefixColDatum(&ran.LowVal[0], colLen, tp) {
if CutDatumByPrefixLen(&ran.LowVal[0], colLen, tp) {
ran.LowExclude = false
}
if FixPrefixColDatum(&ran.HighVal[0], colLen, tp) {
if CutDatumByPrefixLen(&ran.HighVal[0], colLen, tp) {
ran.HighExclude = false
}
}
Expand Down Expand Up @@ -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++ {
FixPrefixColDatum(&ran.LowVal[i], lengths[i], tp[i])
CutDatumByPrefixLen(&ran.LowVal[i], lengths[i], tp[i])
}
lowCut := FixPrefixColDatum(&ran.LowVal[lowTail], lengths[lowTail], tp[lowTail])
lowCut := CutDatumByPrefixLen(&ran.LowVal[lowTail], lengths[lowTail], tp[lowTail])
if lowCut {
ran.LowExclude = false
}
highTail := len(ran.HighVal) - 1
for i := 0; i < highTail; i++ {
FixPrefixColDatum(&ran.HighVal[i], lengths[i], tp[i])
CutDatumByPrefixLen(&ran.HighVal[i], lengths[i], tp[i])
}
highCut := FixPrefixColDatum(&ran.HighVal[highTail], lengths[highTail], tp[highTail])
highCut := CutDatumByPrefixLen(&ran.HighVal[highTail], lengths[highTail], tp[highTail])
if highCut {
ran.HighExclude = false
}
Expand All @@ -444,9 +444,9 @@ func fixPrefixColRange(ranges []*Range, lengths []int, tp []*types.FieldType) bo
return hasCut
}

// FixPrefixColDatum cuts the datum according to the prefix length.
// CutDatumByPrefixLen 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 {
func CutDatumByPrefixLen(v *types.Datum, length int, tp *types.FieldType) bool {
if v.Kind() == types.KindString || v.Kind() == types.KindBytes {
colCharset := tp.Charset
colValue := v.GetBytes()
Expand Down

0 comments on commit 8b03d99

Please sign in to comment.