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

util/ranger: do not convert to binary collate for string values when convertToSortKey is false (#51363) #51373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion pkg/util/ranger/detacher.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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';