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: Fix BatchPointGetPlan.HandleColOffset #54686

Merged
merged 2 commits into from
Jul 22, 2024
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
13 changes: 12 additions & 1 deletion pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,18 @@ func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, ca
batchPointGetPlan.Handles = append(batchPointGetPlan.Handles, kv.IntHandle(ran.LowVal[0].GetInt64()))
}
batchPointGetPlan.accessCols = ds.TblCols
batchPointGetPlan.HandleColOffset = ds.HandleCols.GetCol(0).Index
found := false
for i := range ds.Columns {
if ds.Columns[i].ID == ds.HandleCols.GetCol(0).ID {
batchPointGetPlan.HandleColOffset = ds.Columns[i].Offset
found = true
break
}
}
if !found {
return base.InvalidTask
}

// Add filter condition to table plan now.
if len(candidate.path.TableFilters) > 0 {
batchPointGetPlan.Init(ds.SCtx(), ds.TableStats.ScaleByExpectCnt(accessCnt), ds.Schema().Clone(), ds.OutputNames(), ds.QueryBlockOffset())
Expand Down
13 changes: 13 additions & 0 deletions tests/integrationtest/r/executor/partition/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,16 @@ select space(1), b from issue52198 where b in (1);
space(1) b
1
drop table issue52198;
drop table if exists t;
set tidb_partition_prune_mode=static;
CREATE TABLE t (
a text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
b mediumint(8) unsigned NOT NULL DEFAULT '11075363',
c tinyblob NOT NULL,
PRIMARY KEY (b) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY KEY (b) PARTITIONS 7;
insert into t values ('a' ,6970066, 'a');
update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 );
drop table t;
Defined2014 marked this conversation as resolved.
Show resolved Hide resolved
set tidb_partition_prune_mode=default;
15 changes: 15 additions & 0 deletions tests/integrationtest/t/executor/partition/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,18 @@ create table issue52198 (a int, b int, primary key (b)) partition by hash(b) par
insert into issue52198 values (1,1);
select space(1), b from issue52198 where b in (1);
drop table issue52198;

# TestIssues54667
drop table if exists t;
set tidb_partition_prune_mode=static;
CREATE TABLE t (
a text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
b mediumint(8) unsigned NOT NULL DEFAULT '11075363',
c tinyblob NOT NULL,
PRIMARY KEY (b) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY KEY (b) PARTITIONS 7;
insert into t values ('a' ,6970066, 'a');
update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 );
drop table t;
Defined2014 marked this conversation as resolved.
Show resolved Hide resolved
set tidb_partition_prune_mode=default;