Skip to content

Commit

Permalink
planner: skip index scan plan for tablesample (#54016)
Browse files Browse the repository at this point in the history
close #54015
  • Loading branch information
tangenta committed Jun 14, 2024
1 parent efb8afc commit 6ba9435
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,10 @@ func (ds *DataSource) FindBestTask(prop *property.PhysicalProperty, planCounter
if ds.preferStoreType&h.PreferTiFlash != 0 {
continue
}
// TableSample do not support index scan.
if ds.SampleInfo != nil {
continue
}
idxTask, err := ds.convertToIndexScan(prop, candidate, opt)
if err != nil {
return nil, 0, err
Expand Down
6 changes: 5 additions & 1 deletion tests/integrationtest/r/executor/sample.result
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ a
2100
4500
select a from t use index (idx_0) tablesample regions() order by a;
Error 8128 (HY000): Invalid TABLESAMPLE: plan not supported
Error 1815 (HY000): Internal : Can't find a proper physical plan for this query
DROP TABLE IF EXISTS a;
CREATE TABLE a (pk bigint unsigned primary key clustered, v text);
INSERT INTO a WITH RECURSIVE b(pk) AS (SELECT 1 UNION ALL SELECT pk+1 FROM b WHERE pk < 1000) SELECT pk, 'a' FROM b;
Expand Down Expand Up @@ -224,3 +224,7 @@ a b
1 1
2 2
set @@tidb_partition_prune_mode=default;
drop table if exists t;
create table t (a decimal(62,2) not null, key idx (a), primary key (a) clustered);
select a from t tablesample regions() order by a;
a
7 changes: 6 additions & 1 deletion tests/integrationtest/t/executor/sample.test
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ split table t between (0) and (10000) regions 5;
insert into t values (1000, 1, '1'), (1001, 1, '1'), (2100, 2, '2'), (4500, 3, '3');
create index idx_0 on t (b);
select a from t tablesample regions() order by a;
-- error 8128
-- error 1815
select a from t use index (idx_0) tablesample regions() order by a;

# TestTableSampleUnsignedIntHandle
Expand All @@ -143,3 +143,8 @@ select * from t tablesample regions() order by a;
set @@tidb_partition_prune_mode='dynamic';
select * from t tablesample regions() order by a;
set @@tidb_partition_prune_mode=default;

# TestTableSampleNoIndexScan
drop table if exists t;
create table t (a decimal(62,2) not null, key idx (a), primary key (a) clustered);
select a from t tablesample regions() order by a;

0 comments on commit 6ba9435

Please sign in to comment.