Skip to content

Commit

Permalink
util/ranger: do not convert to binary collate for string values when …
Browse files Browse the repository at this point in the history
…`convertToSortKey` is `false` (#51363) (#51373)

close #51316
  • Loading branch information
ti-chi-bot committed Feb 27, 2024
1 parent 6608c98 commit 7d16cc7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/util/ranger/detacher.go
Expand Up @@ -779,7 +779,10 @@ func (d *rangeDetacher) detachDNFCondAndBuildRangeForIndex(condition *expression
hasResidual = true
}
points := rb.build(item, newTpSlice[0], d.lengths[0], d.convertToSortKey)
tmpNewTp := convertStringFTToBinaryCollate(newTpSlice[0])
tmpNewTp := newTpSlice[0]
if d.convertToSortKey {
tmpNewTp = convertStringFTToBinaryCollate(tmpNewTp)
}
// TODO: restrict the mem usage of ranges
ranges, rangeFallback, err := points2Ranges(d.sctx, points, tmpNewTp, d.rangeMaxSize)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/util/ranger/ranger.go
Expand Up @@ -486,7 +486,10 @@ func (d *rangeDetacher) buildRangeOnColsByCNFCond(newTp []*types.FieldType, eqAn
if rb.err != nil {
return nil, nil, nil, errors.Trace(rb.err)
}
tmpNewTp := convertStringFTToBinaryCollate(newTp[i])
tmpNewTp := newTp[i]
if d.convertToSortKey {
tmpNewTp = convertStringFTToBinaryCollate(tmpNewTp)
}
if i == 0 {
ranges, rangeFallback, err = points2Ranges(d.sctx, point, tmpNewTp, d.rangeMaxSize)
} else {
Expand Down
Expand Up @@ -738,3 +738,15 @@ Projection 10.00 root list_partition_pruning.thash.a
└─Limit 10.00 cop[tikv] offset:0, count:10
└─Selection 10.00 cop[tikv] gt(list_partition_pruning.thash.a, 10)
└─TableFullScan 30.00 cop[tikv] table:thash, partition:p3 keep order:true, stats:pseudo
drop table if exists t;
create table t(col varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL) PARTITION BY KEY (`col`) PARTITIONS 7;
explain format = brief select * from t where col = 'linpin';
id estRows task access object operator info
TableReader 10.00 root data:Selection
└─Selection 10.00 cop[tikv] eq(list_partition_pruning.t.col, "linpin")
└─TableFullScan 10000.00 cop[tikv] table:t, partition:p4 keep order:false, stats:pseudo
explain format = brief select * from t where col = 'LINPIN';
id estRows task access object operator info
TableReader 10.00 root data:Selection
└─Selection 10.00 cop[tikv] eq(list_partition_pruning.t.col, "LINPIN")
└─TableFullScan 10000.00 cop[tikv] table:t, partition:p4 keep order:false, stats:pseudo
Expand Up @@ -180,3 +180,8 @@ explain format='brief' select a from trange use index () where a > 10 order by b
explain format='brief' select a from tlist use index () where a > 10 order by b limit 10;
explain format='brief' select a from thash use index () where a > 10 order by b limit 10;

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

0 comments on commit 7d16cc7

Please sign in to comment.