Skip to content

Commit

Permalink
ranger: fix the case which could have duplicate ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed May 12, 2021
1 parent e40f8c0 commit bbc4a35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions util/ranger/ranger.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ 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++ {
CutDatumByPrefixLen(&ran.LowVal[i], lengths[i], tp[i])
hasCut = CutDatumByPrefixLen(&ran.LowVal[i], lengths[i], tp[i]) || hasCut
}
lowCut := CutDatumByPrefixLen(&ran.LowVal[lowTail], lengths[lowTail], tp[lowTail])
// If the length of the last column of LowVal is equal to the prefix length, LowExclude should be set false.
Expand All @@ -485,13 +485,13 @@ func fixPrefixColRange(ranges []*Range, lengths []int, tp []*types.FieldType) bo
}
highTail := len(ran.HighVal) - 1
for i := 0; i < highTail; i++ {
CutDatumByPrefixLen(&ran.HighVal[i], lengths[i], tp[i])
hasCut = CutDatumByPrefixLen(&ran.HighVal[i], lengths[i], tp[i]) || hasCut
}
highCut := CutDatumByPrefixLen(&ran.HighVal[highTail], lengths[highTail], tp[highTail])
if highCut {
ran.HighExclude = false
}
hasCut = lowCut || highCut
hasCut = hasCut || lowCut || highCut
}
return hasCut
}
Expand Down
10 changes: 9 additions & 1 deletion util/ranger/ranger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ create table t(
index idx_cb(c, a),
index idx_d(d(2)),
index idx_e(e(2)),
index idx_f(f)
index idx_f(f),
index idx_de(d(2), e)
)`)

tests := []struct {
Expand Down Expand Up @@ -620,6 +621,13 @@ create table t(
filterConds: "[like(test.t.f, @%, 92)]",
resultStr: "[[NULL,+inf]]",
},
{
indexPos: 5,
exprStr: "d in ('aab', 'aac') and e = 'a'",
accessConds: "[in(test.t.d, aab, aac) eq(test.t.e, a)]",
filterConds: "[in(test.t.d, aab, aac)]",
resultStr: "[[\"aa\" 0x61,\"aa\" 0x61]]",
},
}

collate.SetNewCollationEnabledForTest(true)
Expand Down

0 comments on commit bbc4a35

Please sign in to comment.