Skip to content

Commit

Permalink
Added support for more cases, like Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Jan 12, 2022
1 parent fc62492 commit 4821fae
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
16 changes: 16 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Projection_3 1.00 root sysdate()->Column#1, sleep(1)->Column#2, sysdate()->Colu
└─TableDual_4 1.00 root rows:1
drop table if exists th;
set @@session.tidb_enable_table_partition = '1';
set @@session.tidb_partition_prune_mode = 'static';
create table th (a int, b int) partition by hash(a) partitions 3;
insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8);
Expand All @@ -378,6 +379,21 @@ PartitionUnion_8 20000.00 root
│ └─TableFullScan_9 10000.00 cop[tikv] table:th, partition:p1 keep order:false, stats:pseudo
└─TableReader_12 10000.00 root data:TableFullScan_11
└─TableFullScan_11 10000.00 cop[tikv] table:th, partition:p2 keep order:false, stats:pseudo
set @@session.tidb_partition_prune_mode = 'dynamic';
desc select * from th where a=-2;
id estRows task access object operator info
TableReader_7 10.00 root partition:p2 data:Selection_6
└─Selection_6 10.00 cop[tikv] eq(test.th.a, -2)
└─TableFullScan_5 10000.00 cop[tikv] table:th keep order:false, stats:pseudo
desc select * from th;
id estRows task access object operator info
TableReader_5 10000.00 root partition:all data:TableFullScan_4
└─TableFullScan_4 10000.00 cop[tikv] table:th keep order:false, stats:pseudo
desc select * from th partition (p2,p1);
id estRows task access object operator info
TableReader_5 10000.00 root partition:p1,p2 data:TableFullScan_4
└─TableFullScan_4 10000.00 cop[tikv] table:th keep order:false, stats:pseudo
set @@session.tidb_partition_prune_mode = DEFAULT;
drop table if exists t;
create table t(a int, b int);
explain format = 'brief' select a != any (select a from t t2) from t t1;
Expand Down
6 changes: 6 additions & 0 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,18 @@ desc select sysdate(), sleep(1), sysdate();
# test select partition table
drop table if exists th;
set @@session.tidb_enable_table_partition = '1';
set @@session.tidb_partition_prune_mode = 'static';
create table th (a int, b int) partition by hash(a) partitions 3;
insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8);
desc select * from th where a=-2;
desc select * from th;
desc select * from th partition (p2,p1);
set @@session.tidb_partition_prune_mode = 'dynamic';
desc select * from th where a=-2;
desc select * from th;
desc select * from th partition (p2,p1);
set @@session.tidb_partition_prune_mode = DEFAULT;

# test != any(subq) and = all(subq)
drop table if exists t;
Expand Down
2 changes: 1 addition & 1 deletion executor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *DeleteExec) deleteSingleTableByChunk(ctx context.Context) error {

datumRow := make([]types.Datum, 0, len(fields))
for i, field := range fields {
if columns[i].ID == model.ExtraPidColID {
if columns[i].ID == model.ExtraPidColID || columns[i].ID == model.ExtraPhysTblID {
continue
}

Expand Down
2 changes: 2 additions & 0 deletions planner/core/plan_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ func (p *PhysicalIndexScan) ToPB(ctx sessionctx.Context, _ kv.StoreType) (*tipb.
for _, col := range p.schema.Columns {
if col.ID == model.ExtraHandleID {
columns = append(columns, model.NewExtraHandleColInfo())
} else if col.ID == model.ExtraPhysTblID {
columns = append(columns, model.NewExtraPhysTblIDColInfo())
} else if col.ID == model.ExtraPidColID {
columns = append(columns, model.NewExtraPartitionIDColInfo())
} else {
Expand Down
10 changes: 0 additions & 10 deletions planner/core/rule_column_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,8 @@ func (p *LogicalUnionScan) PruneColumns(parentUsedCols []*expression.Column, opt
for _, col := range p.Schema().Columns {
if col.ID == model.ExtraPidColID || col.ID == model.ExtraPhysTblID {
parentUsedCols = append(parentUsedCols, col)
cols := p.Schema().Columns
if col != cols[len(cols)-1] {
panic("MJONSS: Assumptions of ExtraPidColID always last is wrong!!!")
}
}
}
// ExtraPidColID should always be last?
/*
if cols[len(cols)-1].ID == model.ExtraPidColID {
parentUsedCols = append(parentUsedCols, col)
}
*/
condCols := expression.ExtractColumnsFromExpressions(nil, p.conditions, nil)
parentUsedCols = append(parentUsedCols, condCols...)
return p.children[0].PruneColumns(parentUsedCols, opt)
Expand Down
9 changes: 9 additions & 0 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ func (s *partitionProcessor) reconstructTableColNames(ds *DataSource) ([]*types.
})
continue
}
if colExpr.ID == model.ExtraPhysTblID {
names = append(names, &types.FieldName{
DBName: ds.DBName,
TblName: ds.tableInfo.Name,
ColName: model.ExtraPhysTblIdName,
OrigColName: model.ExtraPhysTblIdName,
})
continue
}
if colInfo, found := colsInfoMap[colExpr.ID]; found {
names = append(names, &types.FieldName{
DBName: ds.DBName,
Expand Down

0 comments on commit 4821fae

Please sign in to comment.