Skip to content
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

ranger: fix the case which could have duplicate ranges #24590

Merged
merged 4 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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