Skip to content

Commit 7d16cc7

Browse files
authored
util/ranger: do not convert to binary collate for string values when convertToSortKey is false (#51363) (#51373)
close #51316
1 parent 6608c98 commit 7d16cc7

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

pkg/util/ranger/detacher.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,10 @@ func (d *rangeDetacher) detachDNFCondAndBuildRangeForIndex(condition *expression
779779
hasResidual = true
780780
}
781781
points := rb.build(item, newTpSlice[0], d.lengths[0], d.convertToSortKey)
782-
tmpNewTp := convertStringFTToBinaryCollate(newTpSlice[0])
782+
tmpNewTp := newTpSlice[0]
783+
if d.convertToSortKey {
784+
tmpNewTp = convertStringFTToBinaryCollate(tmpNewTp)
785+
}
783786
// TODO: restrict the mem usage of ranges
784787
ranges, rangeFallback, err := points2Ranges(d.sctx, points, tmpNewTp, d.rangeMaxSize)
785788
if err != nil {

pkg/util/ranger/ranger.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ func (d *rangeDetacher) buildRangeOnColsByCNFCond(newTp []*types.FieldType, eqAn
486486
if rb.err != nil {
487487
return nil, nil, nil, errors.Trace(rb.err)
488488
}
489-
tmpNewTp := convertStringFTToBinaryCollate(newTp[i])
489+
tmpNewTp := newTp[i]
490+
if d.convertToSortKey {
491+
tmpNewTp = convertStringFTToBinaryCollate(tmpNewTp)
492+
}
490493
if i == 0 {
491494
ranges, rangeFallback, err = points2Ranges(d.sctx, point, tmpNewTp, d.rangeMaxSize)
492495
} else {

tests/integrationtest/r/planner/core/casetest/partition/integration_partition.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,15 @@ Projection 10.00 root list_partition_pruning.thash.a
738738
└─Limit 10.00 cop[tikv] offset:0, count:10
739739
└─Selection 10.00 cop[tikv] gt(list_partition_pruning.thash.a, 10)
740740
└─TableFullScan 30.00 cop[tikv] table:thash, partition:p3 keep order:true, stats:pseudo
741+
drop table if exists t;
742+
create table t(col varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL) PARTITION BY KEY (`col`) PARTITIONS 7;
743+
explain format = brief select * from t where col = 'linpin';
744+
id estRows task access object operator info
745+
TableReader 10.00 root data:Selection
746+
└─Selection 10.00 cop[tikv] eq(list_partition_pruning.t.col, "linpin")
747+
└─TableFullScan 10000.00 cop[tikv] table:t, partition:p4 keep order:false, stats:pseudo
748+
explain format = brief select * from t where col = 'LINPIN';
749+
id estRows task access object operator info
750+
TableReader 10.00 root data:Selection
751+
└─Selection 10.00 cop[tikv] eq(list_partition_pruning.t.col, "LINPIN")
752+
└─TableFullScan 10000.00 cop[tikv] table:t, partition:p4 keep order:false, stats:pseudo

tests/integrationtest/t/planner/core/casetest/partition/integration_partition.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,8 @@ explain format='brief' select a from trange use index () where a > 10 order by b
180180
explain format='brief' select a from tlist use index () where a > 10 order by b limit 10;
181181
explain format='brief' select a from thash use index () where a > 10 order by b limit 10;
182182

183+
# TestIssue51316
184+
drop table if exists t;
185+
create table t(col varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL) PARTITION BY KEY (`col`) PARTITIONS 7;
186+
explain format = brief select * from t where col = 'linpin';
187+
explain format = brief select * from t where col = 'LINPIN';

0 commit comments

Comments
 (0)