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

planner: Using converted value in newBatchPointGetPlan, fix for partitioned table and IN #57011

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
8 changes: 4 additions & 4 deletions pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ func newBatchPointGetPlan(
if dval == nil {
return nil
}
values[permIndex] = innerX.Datum
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: innerX.Datum})
values[permIndex] = *dval
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: *dval})
case *driver.ParamMarkerExpr:
con, err := expression.ParamMarkerExpression(ctx, innerX, true)
if err != nil {
Expand All @@ -832,12 +832,12 @@ func newBatchPointGetPlan(
if dval == nil {
return nil
}
values[permIndex] = innerX.Datum
values[permIndex] = *dval
valuesParams[permIndex] = con
if initTypes {
indexTypes[permIndex] = &colInfos[index].FieldType
}
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: innerX.Datum})
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: *dval})
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,19 @@ 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
drop table if exists t;
CREATE TABLE `t` (`tenant_id` bigint(20) NOT NULL DEFAULT '0',`order_id` bigint(20) NOT NULL DEFAULT '0',UNIQUE KEY `uk_ten_ord` (`order_id`, `tenant_id`)) PARTITION BY HASH(`tenant_id`) PARTITIONS 32;
INSERT INTO t(tenant_id, order_id) VALUES (123, 456);
select * from t where (tenant_id, order_id) in (('123','456'));
tenant_id order_id
123 456
select * from t where (tenant_id, order_id) in (('0123','456'));
tenant_id order_id
123 456
alter table t remove partitioning;
select * from t where (tenant_id, order_id) in (('123','456'));
tenant_id order_id
123 456
select * from t where (tenant_id, order_id) in (('0123','456'));
tenant_id order_id
123 456
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,13 @@ 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';

# TestIssue54746
drop table if exists t;
CREATE TABLE `t` (`tenant_id` bigint(20) NOT NULL DEFAULT '0',`order_id` bigint(20) NOT NULL DEFAULT '0',UNIQUE KEY `uk_ten_ord` (`order_id`, `tenant_id`)) PARTITION BY HASH(`tenant_id`) PARTITIONS 32;
INSERT INTO t(tenant_id, order_id) VALUES (123, 456);
select * from t where (tenant_id, order_id) in (('123','456'));
select * from t where (tenant_id, order_id) in (('0123','456'));
alter table t remove partitioning;
select * from t where (tenant_id, order_id) in (('123','456'));
select * from t where (tenant_id, order_id) in (('0123','456'));