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)

close #51316
  • Loading branch information
time-and-fate authored Feb 27, 2024
1 parent dc1c410 commit 961159c
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
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,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
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 961159c

Please sign in to comment.