diff --git a/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go b/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go index e16fb9f52df7a..56753578326a6 100644 --- a/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go +++ b/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go @@ -232,22 +232,26 @@ func TestPessimisticLockOnPartitionForIndexMerge(t *testing.T) { " ├─IndexReader(Build) 3.00 root index:IndexFullScan", " │ └─IndexFullScan 3.00 cop[tikv] table:t2, index:c_datetime(c_datetime) keep order:false", " └─PartitionUnion(Probe) 5545.21 root ", - " ├─IndexMerge 5542.21 root type: union", - " │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo", - " │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - " │ └─TableRowIDScan(Probe) 5542.21 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - " ├─IndexMerge 1.00 root type: union", - " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c1(c1) range:[-inf,10), keep order:false", - " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c2(c2) range:[-inf,10), keep order:false", - " │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", - " ├─IndexMerge 1.00 root type: union", - " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c1(c1) range:[-inf,10), keep order:false", - " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c2(c2) range:[-inf,10), keep order:false", - " │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p2 keep order:false", - " └─IndexMerge 1.00 root type: union", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c1(c1) range:[-inf,10), keep order:false", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c2(c2) range:[-inf,10), keep order:false", - " └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p3 keep order:false", + " ├─Projection 5542.21 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid", + " │ └─IndexMerge 5542.21 root type: union", + " │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo", + " │ ├─IndexRangeScan(Build) 3323.33 cop[tikv] table:t1, partition:p0, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", + " │ └─TableRowIDScan(Probe) 5542.21 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", + " ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid", + " │ └─IndexMerge 1.00 root type: union", + " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c1(c1) range:[-inf,10), keep order:false", + " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p1, index:c2(c2) range:[-inf,10), keep order:false", + " │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p1 keep order:false", + " ├─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid", + " │ └─IndexMerge 1.00 root type: union", + " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c1(c1) range:[-inf,10), keep order:false", + " │ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p2, index:c2(c2) range:[-inf,10), keep order:false", + " │ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p2 keep order:false", + " └─Projection 1.00 root test.t1.c_datetime, test.t1.c1, test.t1._tidb_rowid, test.t1._tidb_tid", + " └─IndexMerge 1.00 root type: union", + " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c1(c1) range:[-inf,10), keep order:false", + " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t1, partition:p3, index:c2(c2) range:[-inf,10), keep order:false", + " └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t1, partition:p3 keep order:false", )) tk.MustQuery(`select /*+ use_index_merge(t1) */ c1 from t1 join t2 on t1.c_datetime >= t2.c_datetime @@ -372,20 +376,21 @@ func TestIntersectionWithDifferentConcurrency(t *testing.T) { for _, concurrency := range execCon { tk.MustExec(fmt.Sprintf("set tidb_executor_concurrency = %d", concurrency)) for i := 0; i < 2; i++ { + sql := "select /*+ use_index_merge(t1, primary, c2, c3) */ c1 from t1 where c2 < 1024 and c3 > 1024" if i == 0 { // Dynamic mode. tk.MustExec("set tidb_partition_prune_mode = 'dynamic'") - res := tk.MustQuery("explain select /*+ use_index_merge(t1, primary, c2, c3) */ c1 from t1 where c2 < 1024 and c3 > 1024") - require.Contains(t, res.Rows()[1][0], "IndexMerge") + tk.MustHavePlan(sql, "IndexMerge") + tk.MustNotHavePlan(sql, "PartitionUnion") } else { tk.MustExec("set tidb_partition_prune_mode = 'static'") - res := tk.MustQuery("explain select /*+ use_index_merge(t1, primary, c2, c3) */ c1 from t1 where c2 < 1024 and c3 > 1024") if tblIdx == 0 { // partition table - require.Contains(t, res.Rows()[1][0], "PartitionUnion") - require.Contains(t, res.Rows()[2][0], "IndexMerge") + tk.MustHavePlan(sql, "IndexMerge") + tk.MustHavePlan(sql, "PartitionUnion") } else { - require.Contains(t, res.Rows()[1][0], "IndexMerge") + tk.MustHavePlan(sql, "IndexMerge") + tk.MustNotHavePlan(sql, "PartitionUnion") } } for i := 0; i < queryCnt; i++ { diff --git a/pkg/planner/core/rule_column_pruning.go b/pkg/planner/core/rule_column_pruning.go index dce44e08ac1c0..dfb9e8433b750 100644 --- a/pkg/planner/core/rule_column_pruning.go +++ b/pkg/planner/core/rule_column_pruning.go @@ -275,6 +275,9 @@ func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column, opt if !hasBeenUsed { parentUsedCols = make([]*expression.Column, len(p.schema.Columns)) copy(parentUsedCols, p.schema.Columns) + for i := range used { + used[i] = true + } } for _, child := range p.Children() { err := child.PruneColumns(parentUsedCols, opt, p) @@ -284,16 +287,14 @@ func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column, opt } prunedColumns := make([]*expression.Column, 0) - if hasBeenUsed { - // keep the schema of LogicalUnionAll same as its children's - used := expression.GetUsedList(p.SCtx(), p.children[0].Schema().Columns, p.schema) - for i := len(used) - 1; i >= 0; i-- { - if !used[i] { - prunedColumns = append(prunedColumns, p.schema.Columns[i]) - p.schema.Columns = append(p.schema.Columns[:i], p.schema.Columns[i+1:]...) - } + for i := len(used) - 1; i >= 0; i-- { + if !used[i] { + prunedColumns = append(prunedColumns, p.schema.Columns[i]) + p.schema.Columns = append(p.schema.Columns[:i], p.schema.Columns[i+1:]...) } - appendColumnPruneTraceStep(p, prunedColumns, opt) + } + appendColumnPruneTraceStep(p, prunedColumns, opt) + if hasBeenUsed { // It's possible that the child operator adds extra columns to the schema. // Currently, (*LogicalAggregation).PruneColumns() might do this. // But we don't need such columns, so we add an extra Projection to prune this column when this happened. diff --git a/tests/integrationtest/r/planner/core/casetest/integration.result b/tests/integrationtest/r/planner/core/casetest/integration.result index 7f6d88be5f824..a6622f77a4b9d 100644 --- a/tests/integrationtest/r/planner/core/casetest/integration.result +++ b/tests/integrationtest/r/planner/core/casetest/integration.result @@ -1420,23 +1420,27 @@ create table t1 (a int, b int); create table t2_part (a int, b int, key(a)) partition by hash(a) partitions 4; explain select /*+ TIDB_INLJ(t2_part@sel_2) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20); id estRows task access object operator info -HashJoin_15 2658.67 root anti semi join, equal:[eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a)] -├─PartitionUnion_19(Build) 13293.33 root -│ ├─TableReader_22 3323.33 root data:Selection_21 -│ │ └─Selection_21 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) -│ │ └─TableFullScan_20 10000.00 cop[tikv] table:t2_part, partition:p0 keep order:false, stats:pseudo -│ ├─TableReader_25 3323.33 root data:Selection_24 -│ │ └─Selection_24 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) -│ │ └─TableFullScan_23 10000.00 cop[tikv] table:t2_part, partition:p1 keep order:false, stats:pseudo -│ ├─TableReader_28 3323.33 root data:Selection_27 -│ │ └─Selection_27 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) -│ │ └─TableFullScan_26 10000.00 cop[tikv] table:t2_part, partition:p2 keep order:false, stats:pseudo -│ └─TableReader_31 3323.33 root data:Selection_30 -│ └─Selection_30 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) -│ └─TableFullScan_29 10000.00 cop[tikv] table:t2_part, partition:p3 keep order:false, stats:pseudo -└─TableReader_18(Probe) 3323.33 root data:Selection_17 - └─Selection_17 3323.33 cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) - └─TableFullScan_16 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +HashJoin_19 2658.67 root anti semi join, equal:[eq(planner__core__casetest__integration.t1.a, planner__core__casetest__integration.t2_part.a)] +├─PartitionUnion_23(Build) 13293.33 root +│ ├─Projection_24 3323.33 root planner__core__casetest__integration.t2_part.a +│ │ └─TableReader_27 3323.33 root data:Selection_26 +│ │ └─Selection_26 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) +│ │ └─TableFullScan_25 10000.00 cop[tikv] table:t2_part, partition:p0 keep order:false, stats:pseudo +│ ├─Projection_28 3323.33 root planner__core__casetest__integration.t2_part.a +│ │ └─TableReader_31 3323.33 root data:Selection_30 +│ │ └─Selection_30 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) +│ │ └─TableFullScan_29 10000.00 cop[tikv] table:t2_part, partition:p1 keep order:false, stats:pseudo +│ ├─Projection_32 3323.33 root planner__core__casetest__integration.t2_part.a +│ │ └─TableReader_35 3323.33 root data:Selection_34 +│ │ └─Selection_34 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) +│ │ └─TableFullScan_33 10000.00 cop[tikv] table:t2_part, partition:p2 keep order:false, stats:pseudo +│ └─Projection_36 3323.33 root planner__core__casetest__integration.t2_part.a +│ └─TableReader_39 3323.33 root data:Selection_38 +│ └─Selection_38 3323.33 cop[tikv] lt(planner__core__casetest__integration.t2_part.b, 20) +│ └─TableFullScan_37 10000.00 cop[tikv] table:t2_part, partition:p3 keep order:false, stats:pseudo +└─TableReader_22(Probe) 3323.33 root data:Selection_21 + └─Selection_21 3323.33 cop[tikv] lt(planner__core__casetest__integration.t1.b, 10) + └─TableFullScan_20 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo Level Code Message Warning 1105 disable dynamic pruning due to t2_part has no global stats Warning 1815 Optimizer Hint /*+ INL_JOIN(t2_part) */ or /*+ TIDB_INLJ(t2_part) */ is inapplicable diff --git a/tests/integrationtest/r/planner/core/casetest/partition/integration_partition.result b/tests/integrationtest/r/planner/core/casetest/partition/integration_partition.result index 51c9c68b2d67c..dd34b8ef6e571 100644 --- a/tests/integrationtest/r/planner/core/casetest/partition/integration_partition.result +++ b/tests/integrationtest/r/planner/core/casetest/partition/integration_partition.result @@ -539,21 +539,23 @@ Projection 3.33 root list_partition_pruning.t.a └─TableRowIDScan 3333.33 cop[tikv] table:t keep order:false, stats:pseudo explain format='brief' select a from trange use index (ia) where a > 10 and c = 10 order by a limit 10; id estRows task access object operator info -Projection 10.00 root list_partition_pruning.trange.a -└─TopN 10.00 root list_partition_pruning.trange.a, offset:0, count:10 - └─PartitionUnion 10.00 root - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.trange.a, list_partition_pruning.trange.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:trange, partition:p1, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.trange.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:trange, partition:p1 keep order:false, stats:pseudo - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.trange.a, list_partition_pruning.trange.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:trange, partition:p2, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.trange.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:trange, partition:p2 keep order:false, stats:pseudo +TopN 10.00 root list_partition_pruning.trange.a, offset:0, count:10 +└─PartitionUnion 10.00 root + ├─Projection 3.33 root list_partition_pruning.trange.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.trange.a, list_partition_pruning.trange.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:trange, partition:p1, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.trange.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:trange, partition:p1 keep order:false, stats:pseudo + ├─Projection 3.33 root list_partition_pruning.trange.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.trange.a, list_partition_pruning.trange.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:trange, partition:p2, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.trange.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:trange, partition:p2 keep order:false, stats:pseudo + └─Projection 3.33 root list_partition_pruning.trange.a └─Limit 3.33 root offset:0, count:10 └─Projection 3.33 root list_partition_pruning.trange.a, list_partition_pruning.trange.c └─IndexLookUp 3.33 root @@ -562,15 +564,16 @@ Projection 10.00 root list_partition_pruning.trange.a └─TableRowIDScan 3333.33 cop[tikv] table:trange, partition:p3 keep order:false, stats:pseudo explain format='brief' select a from tlist use index (ia) where a > 10 and c = 10 order by a limit 10; id estRows task access object operator info -Projection 6.67 root list_partition_pruning.tlist.a -└─TopN 6.67 root list_partition_pruning.tlist.a, offset:0, count:10 - └─PartitionUnion 6.67 root - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.tlist.a, list_partition_pruning.tlist.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:tlist, partition:p0, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.tlist.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:tlist, partition:p0 keep order:false, stats:pseudo +TopN 6.67 root list_partition_pruning.tlist.a, offset:0, count:10 +└─PartitionUnion 6.67 root + ├─Projection 3.33 root list_partition_pruning.tlist.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.tlist.a, list_partition_pruning.tlist.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:tlist, partition:p0, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.tlist.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:tlist, partition:p0 keep order:false, stats:pseudo + └─Projection 3.33 root list_partition_pruning.tlist.a └─Limit 3.33 root offset:0, count:10 └─Projection 3.33 root list_partition_pruning.tlist.a, list_partition_pruning.tlist.c └─IndexLookUp 3.33 root @@ -579,27 +582,30 @@ Projection 6.67 root list_partition_pruning.tlist.a └─TableRowIDScan 3333.33 cop[tikv] table:tlist, partition:p1 keep order:false, stats:pseudo explain format='brief' select a from thash use index (ia) where a > 10 and c = 10 order by a limit 10; id estRows task access object operator info -Projection 10.00 root list_partition_pruning.thash.a -└─TopN 10.00 root list_partition_pruning.thash.a, offset:0, count:10 - └─PartitionUnion 13.33 root - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p0, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p0 keep order:false, stats:pseudo - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p1, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p1 keep order:false, stats:pseudo - ├─Limit 3.33 root offset:0, count:10 - │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c - │ └─IndexLookUp 3.33 root - │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p2, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo - │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) - │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p2 keep order:false, stats:pseudo +TopN 10.00 root list_partition_pruning.thash.a, offset:0, count:10 +└─PartitionUnion 13.33 root + ├─Projection 3.33 root list_partition_pruning.thash.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p0, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p0 keep order:false, stats:pseudo + ├─Projection 3.33 root list_partition_pruning.thash.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p1, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p1 keep order:false, stats:pseudo + ├─Projection 3.33 root list_partition_pruning.thash.a + │ └─Limit 3.33 root offset:0, count:10 + │ └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c + │ └─IndexLookUp 3.33 root + │ ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:thash, partition:p2, index:ia(a) range:(10,+inf], keep order:true, stats:pseudo + │ └─Selection(Probe) 3.33 cop[tikv] eq(list_partition_pruning.thash.c, 10) + │ └─TableRowIDScan 3333.33 cop[tikv] table:thash, partition:p2 keep order:false, stats:pseudo + └─Projection 3.33 root list_partition_pruning.thash.a └─Limit 3.33 root offset:0, count:10 └─Projection 3.33 root list_partition_pruning.thash.a, list_partition_pruning.thash.c └─IndexLookUp 3.33 root diff --git a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result index 9a5474ce1b188..920b962398a76 100644 --- a/tests/integrationtest/r/planner/core/issuetest/planner_issue.result +++ b/tests/integrationtest/r/planner/core/issuetest/planner_issue.result @@ -180,6 +180,84 @@ LEFT JOIN tmp3 c3 ON c3.id = '1'; id id 1 1 1 1 +drop table if exists t; +create table t(a int, b int); +set @@tidb_max_chunk_size = 32; +insert into t values(1, 1); +insert into t select a+1, a+1 from t; +insert into t select a+2, a+2 from t; +insert into t select a+4, a+4 from t; +insert into t select a+8, a+8 from t; +insert into t select a+16, a+16 from t; +insert into t select a+32, a+32 from t; +select a from (select 100 as a, 100 as b union all select * from t) t where b != 0; +a +100 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +set @@tidb_max_chunk_size = default; drop table if exists t1, t2; create table t1(a varchar(20) collate utf8mb4_bin, index ia(a)); insert into t1 value('测试'),('测试 '); diff --git a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test index 372e9eb8a67a6..45d79ba30b5fa 100644 --- a/tests/integrationtest/t/planner/core/issuetest/planner_issue.test +++ b/tests/integrationtest/t/planner/core/issuetest/planner_issue.test @@ -137,6 +137,21 @@ FROM LEFT JOIN tmp3 c2 ON c2.id = '1' LEFT JOIN tmp3 c3 ON c3.id = '1'; +# https://github.com/pingcap/tidb/issues/48755 +drop table if exists t; +create table t(a int, b int); +set @@tidb_max_chunk_size = 32; +# insert into more than 32 rows to the table. +insert into t values(1, 1); +insert into t select a+1, a+1 from t; +insert into t select a+2, a+2 from t; +insert into t select a+4, a+4 from t; +insert into t select a+8, a+8 from t; +insert into t select a+16, a+16 from t; +insert into t select a+32, a+32 from t; +select a from (select 100 as a, 100 as b union all select * from t) t where b != 0; +set @@tidb_max_chunk_size = default; + # https://github.com/pingcap/tidb/issues/48821 drop table if exists t1, t2; create table t1(a varchar(20) collate utf8mb4_bin, index ia(a));