From 1c96a093d2a0a9f81594389e50d2a73cc762e9e0 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Tue, 25 Aug 2020 16:09:31 +0800 Subject: [PATCH 1/2] cherry pick #18516 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 104 +++++++++++++++++++++++++++++++++ planner/core/find_best_task.go | 16 ++++- planner/core/initialize.go | 19 ++++++ planner/core/physical_plans.go | 18 +++++- planner/core/point_get_plan.go | 8 --- planner/core/task.go | 13 ++++- 6 files changed, 166 insertions(+), 12 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 238e038dcaeaa..0933b31264dcf 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6558,6 +6558,110 @@ func (s *testIntegrationSuite) TestIssue17727(c *C) { tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) } +<<<<<<< HEAD +======= +func (s *testIntegrationSerialSuite) TestIssue17891(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');") + tk.MustExec("drop table t") + tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');") +} + +func (s *testIntegrationSerialSuite) TestIssue17233(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists table_int") + tk.MustExec(`CREATE TABLE table_int ( + id_0 int(16) NOT NULL AUTO_INCREMENT, + col_int_0 int(16) DEFAULT NULL, + PRIMARY KEY (id_0), + KEY fvclc (id_0,col_int_0));`) + tk.MustExec("INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0)") + + tk.MustExec("drop table if exists table_varchar") + tk.MustExec(`CREATE TABLE table_varchar ( + id_2 int(16) NOT NULL AUTO_INCREMENT, + col_varchar_2 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_2));`) + tk.MustExec(`INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,'');`) + + tk.MustExec("drop table if exists table_float_varchar") + tk.MustExec(`CREATE TABLE table_int_float_varchar ( + id_6 int(16) NOT NULL AUTO_INCREMENT, + col_int_6 int(16) NOT NULL, + col_float_6 float DEFAULT NULL, + col_varchar_6 varchar(511) DEFAULT NULL, + PRIMARY KEY (id_6,col_int_6) + ) + PARTITION BY RANGE ( col_int_6 ) ( + PARTITION p0 VALUES LESS THAN (1), + PARTITION p2 VALUES LESS THAN (1000), + PARTITION p3 VALUES LESS THAN (10000), + PARTITION p5 VALUES LESS THAN (1000000), + PARTITION p7 VALUES LESS THAN (100000000), + PARTITION p9 VALUES LESS THAN (10000000000), + PARTITION p10 VALUES LESS THAN (100000000000), + PARTITION pn VALUES LESS THAN (MAXVALUE));`) + tk.MustExec(`INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1');`) + + tk.MustExec("drop table if exists table_float") + tk.MustExec(`CREATE TABLE table_float ( + id_1 int(16) NOT NULL AUTO_INCREMENT, + col_float_1 float DEFAULT NULL, + PRIMARY KEY (id_1), + KEY zbjus (id_1,col_float_1));`) + tk.MustExec(`INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1);`) + + tk.MustExec("drop view if exists view_4") + tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS + SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ + tmp1.id_6 AS col_1, + tmp1.col_int_6 AS col_2, + tmp1.col_float_6 AS col_3, + tmp1.col_varchar_6 AS col_4, + tmp2.id_2 AS col_5, + tmp2.col_varchar_2 AS col_6, + tmp3.id_0 AS col_7, + tmp3.col_int_0 AS col_8, + tmp4.id_1 AS col_9, + tmp4.col_float_1 AS col_10 + FROM (( + test.table_int_float_varchar AS tmp1 LEFT JOIN + test.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL + ) JOIN + test.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) + JOIN + test.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5;`) + + tk.MustExec("drop view if exists view_10") + tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS + SELECT table_int.id_0 AS col_1, + table_int.col_int_0 AS col_2 + FROM test.table_int + WHERE + ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) + ORDER BY col_1,col_2 + LIMIT 5,9;`) + + tk.MustQuery("SELECT col_1 FROM test.view_10").Sort().Check(testkit.Rows("16", "18", "19")) + tk.MustQuery("SELECT col_1 FROM test.view_4").Sort().Check(testkit.Rows("8", "8", "8", "8", "8")) + tk.MustQuery("SELECT view_10.col_1 FROM view_4 JOIN view_10").Check(testkit.Rows("16", "16", "16", "16", "16", "18", "18", "18", "18", "18", "19", "19", "19", "19", "19")) +} + +func (s *testIntegrationSuite) TestIssue18515(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b json, c int AS (JSON_EXTRACT(b, '$.population')), key(c));") + tk.MustExec("select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c;") +} + +>>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) func (s *testIntegrationSerialSuite) TestIssue17989(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index a7fa84cb76eb6..fdb627605226b 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -703,7 +703,22 @@ func (ds *DataSource) buildIndexMergeTableScan(prop *property.PhysicalProperty, physicalTableID: ds.physicalTableID, }.Init(ds.ctx, ds.blockOffset) ts.SetSchema(ds.schema.Clone()) +<<<<<<< HEAD ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) +======= + if ts.HandleCols == nil { + handleCol := ds.getPKIsHandleCol() + if handleCol == nil { + handleCol, _ = ts.appendExtraHandleCol(ds) + } + ts.HandleCols = NewIntHandleCols(handleCol) + } + var err error + ts.HandleCols, err = ts.HandleCols.ResolveIndices(ts.schema) + if err != nil { + return nil, 0, err + } +>>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) if ts.Table.PKIsHandle { if pkColInfo := ts.Table.GetPkColInfo(); pkColInfo != nil { if ds.statisticTable.Columns[pkColInfo.ID] != nil { @@ -799,7 +814,6 @@ func (ds *DataSource) convertToIndexScan(prop *property.PhysicalProperty, candid physicalTableID: ds.physicalTableID, }.Init(ds.ctx, is.blockOffset) ts.SetSchema(ds.schema.Clone()) - ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) cop.tablePlan = ts } cop.cst = cost diff --git a/planner/core/initialize.go b/planner/core/initialize.go index b7e488a4510a7..44e42823ace03 100644 --- a/planner/core/initialize.go +++ b/planner/core/initialize.go @@ -459,6 +459,25 @@ func (p BatchPointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInf return &p } +<<<<<<< HEAD +======= +// Init initializes PointGetPlan. +func (p PointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PointGetPlan { + p.basePlan = newBasePlan(ctx, plancodec.TypePointGet, offset) + p.stats = stats + p.Columns = ExpandVirtualColumn(p.Columns, p.schema, p.TblInfo.Columns) + return &p +} + +func flattenTreePlan(plan PhysicalPlan, plans []PhysicalPlan) []PhysicalPlan { + plans = append(plans, plan) + for _, child := range plan.Children() { + plans = flattenTreePlan(child, plans) + } + return plans +} + +>>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) // flattenPushDownPlan converts a plan tree to a list, whose head is the leaf node like table scan. func flattenPushDownPlan(p PhysicalPlan) []PhysicalPlan { plans := make([]PhysicalPlan, 0, 5) diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 00697ddd628e7..3b4c7e9d99cd3 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -263,6 +263,16 @@ func (ts *PhysicalTableScan) IsPartition() (bool, int64) { // ExpandVirtualColumn expands the virtual column's dependent columns to ts's schema and column. func ExpandVirtualColumn(columns []*model.ColumnInfo, schema *expression.Schema, colsInfo []*model.ColumnInfo) []*model.ColumnInfo { + copyColumn := make([]*model.ColumnInfo, len(columns)) + copy(copyColumn, columns) + var extraColumn *expression.Column + var extraColumnModel *model.ColumnInfo + if schema.Columns[len(schema.Columns)-1].ID == model.ExtraHandleID { + extraColumn = schema.Columns[len(schema.Columns)-1] + extraColumnModel = copyColumn[len(copyColumn)-1] + schema.Columns = schema.Columns[:len(schema.Columns)-1] + copyColumn = copyColumn[:len(copyColumn)-1] + } schemaColumns := schema.Columns for _, col := range schemaColumns { if col.VirtualExpr == nil { @@ -273,11 +283,15 @@ func ExpandVirtualColumn(columns []*model.ColumnInfo, schema *expression.Schema, for _, baseCol := range baseCols { if !schema.Contains(baseCol) { schema.Columns = append(schema.Columns, baseCol) - columns = append(columns, FindColumnInfoByID(colsInfo, baseCol.ID)) + copyColumn = append(copyColumn, FindColumnInfoByID(colsInfo, baseCol.ID)) } } } - return columns + if extraColumn != nil { + schema.Columns = append(schema.Columns, extraColumn) + copyColumn = append(copyColumn, extraColumnModel) + } + return copyColumn } //SetIsChildOfIndexLookUp is to set the bool if is a child of IndexLookUpReader diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index a537f46eb342b..a65c8f14f6fad 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -73,14 +73,6 @@ type nameValuePair struct { param *driver.ParamMarkerExpr } -// Init initializes PointGetPlan. -func (p PointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PointGetPlan { - p.basePlan = newBasePlan(ctx, plancodec.TypePointGet, offset) - p.stats = stats - p.Columns = ExpandVirtualColumn(p.Columns, p.schema, p.TblInfo.Columns) - return &p -} - // Schema implements the Plan interface. func (p *PointGetPlan) Schema() *expression.Schema { return p.schema diff --git a/planner/core/task.go b/planner/core/task.go index b38bc98de3d78..045faa2985ceb 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -648,6 +648,18 @@ func finishCopTask(ctx sessionctx.Context, task task) task { // Network cost of transferring rows of table scan to TiDB. if t.tablePlan != nil { t.cst += t.count() * sessVars.NetworkFactor * t.tblColHists.GetAvgRowSize(ctx, t.tablePlan.Schema().Columns, false, false) + + tp := t.tablePlan + for len(tp.Children()) > 0 { + if len(tp.Children()) == 1 { + tp = tp.Children()[0] + } else { + join := tp.(*PhysicalBroadCastJoin) + tp = join.children[1-join.InnerChildIdx] + } + } + ts := tp.(*PhysicalTableScan) + ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) } t.cst /= copIterWorkers newTask := &rootTask{ @@ -676,7 +688,6 @@ func finishCopTask(ctx sessionctx.Context, task task) task { StoreType: ts.StoreType, }.Init(ctx, t.tablePlan.SelectBlockOffset()) p.stats = t.tablePlan.statsInfo() - ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) newTask.p = p } From 8ab3916460d6946850cb4cc94d602a806cf5faf9 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Tue, 25 Aug 2020 17:21:52 +0800 Subject: [PATCH 2/2] done Signed-off-by: wjhuang2016 --- expression/integration_test.go | 96 ---------------------------------- planner/core/find_best_task.go | 16 ------ planner/core/initialize.go | 11 ---- planner/core/task.go | 7 +-- 4 files changed, 1 insertion(+), 129 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 0933b31264dcf..88fef13eb6904 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6558,101 +6558,6 @@ func (s *testIntegrationSuite) TestIssue17727(c *C) { tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) } -<<<<<<< HEAD -======= -func (s *testIntegrationSerialSuite) TestIssue17891(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');") - tk.MustExec("drop table t") - tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');") -} - -func (s *testIntegrationSerialSuite) TestIssue17233(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists table_int") - tk.MustExec(`CREATE TABLE table_int ( - id_0 int(16) NOT NULL AUTO_INCREMENT, - col_int_0 int(16) DEFAULT NULL, - PRIMARY KEY (id_0), - KEY fvclc (id_0,col_int_0));`) - tk.MustExec("INSERT INTO table_int VALUES (1,NULL),(2,NULL),(3,65535),(4,1),(5,0),(6,NULL),(7,-1),(8,65535),(9,NULL),(10,65535),(11,-1),(12,0),(13,-1),(14,1),(15,65535),(16,0),(17,1),(18,0),(19,0)") - - tk.MustExec("drop table if exists table_varchar") - tk.MustExec(`CREATE TABLE table_varchar ( - id_2 int(16) NOT NULL AUTO_INCREMENT, - col_varchar_2 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_2));`) - tk.MustExec(`INSERT INTO table_varchar VALUES (1,''),(2,''),(3,''),(4,''),(5,''),(6,''),(7,''),(8,''),(9,''),(10,''),(11,''),(12,'');`) - - tk.MustExec("drop table if exists table_float_varchar") - tk.MustExec(`CREATE TABLE table_int_float_varchar ( - id_6 int(16) NOT NULL AUTO_INCREMENT, - col_int_6 int(16) NOT NULL, - col_float_6 float DEFAULT NULL, - col_varchar_6 varchar(511) DEFAULT NULL, - PRIMARY KEY (id_6,col_int_6) - ) - PARTITION BY RANGE ( col_int_6 ) ( - PARTITION p0 VALUES LESS THAN (1), - PARTITION p2 VALUES LESS THAN (1000), - PARTITION p3 VALUES LESS THAN (10000), - PARTITION p5 VALUES LESS THAN (1000000), - PARTITION p7 VALUES LESS THAN (100000000), - PARTITION p9 VALUES LESS THAN (10000000000), - PARTITION p10 VALUES LESS THAN (100000000000), - PARTITION pn VALUES LESS THAN (MAXVALUE));`) - tk.MustExec(`INSERT INTO table_int_float_varchar VALUES (1,-1,0.1,'0000-00-00 00:00:00'),(2,0,0,NULL),(3,-1,1,NULL),(4,0,NULL,NULL),(7,0,0.5,NULL),(8,0,0,NULL),(10,-1,0,'-1'),(5,1,-0.1,NULL),(6,1,0.1,NULL),(9,65535,0,'1');`) - - tk.MustExec("drop table if exists table_float") - tk.MustExec(`CREATE TABLE table_float ( - id_1 int(16) NOT NULL AUTO_INCREMENT, - col_float_1 float DEFAULT NULL, - PRIMARY KEY (id_1), - KEY zbjus (id_1,col_float_1));`) - tk.MustExec(`INSERT INTO table_float VALUES (1,NULL),(2,-0.1),(3,-1),(4,NULL),(5,-0.1),(6,0),(7,0),(8,-1),(9,NULL),(10,NULL),(11,0.1),(12,-1);`) - - tk.MustExec("drop view if exists view_4") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_4 (col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10) AS - SELECT /*+ USE_INDEX(table_int fvclc, fvclc)*/ - tmp1.id_6 AS col_1, - tmp1.col_int_6 AS col_2, - tmp1.col_float_6 AS col_3, - tmp1.col_varchar_6 AS col_4, - tmp2.id_2 AS col_5, - tmp2.col_varchar_2 AS col_6, - tmp3.id_0 AS col_7, - tmp3.col_int_0 AS col_8, - tmp4.id_1 AS col_9, - tmp4.col_float_1 AS col_10 - FROM (( - test.table_int_float_varchar AS tmp1 LEFT JOIN - test.table_varchar AS tmp2 ON ((NULL<=tmp2.col_varchar_2)) IS NULL - ) JOIN - test.table_int AS tmp3 ON (1.117853833115198e-03!=tmp1.col_int_6)) - JOIN - test.table_float AS tmp4 ON !((1900370398268920328=0e+00)) WHERE ((''<='{Gm~PcZNb') OR (tmp2.id_2 OR tmp3.col_int_0)) ORDER BY col_1,col_2,col_3,col_4,col_5,col_6,col_7,col_8,col_9,col_10 LIMIT 20580,5;`) - - tk.MustExec("drop view if exists view_10") - tk.MustExec(`CREATE DEFINER='root'@'127.0.0.1' VIEW view_10 (col_1, col_2) AS - SELECT table_int.id_0 AS col_1, - table_int.col_int_0 AS col_2 - FROM test.table_int - WHERE - ((-1e+00=1) OR (0e+00>=table_int.col_int_0)) - ORDER BY col_1,col_2 - LIMIT 5,9;`) - - tk.MustQuery("SELECT col_1 FROM test.view_10").Sort().Check(testkit.Rows("16", "18", "19")) - tk.MustQuery("SELECT col_1 FROM test.view_4").Sort().Check(testkit.Rows("8", "8", "8", "8", "8")) - tk.MustQuery("SELECT view_10.col_1 FROM view_4 JOIN view_10").Check(testkit.Rows("16", "16", "16", "16", "16", "18", "18", "18", "18", "18", "19", "19", "19", "19", "19")) -} - func (s *testIntegrationSuite) TestIssue18515(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -6661,7 +6566,6 @@ func (s *testIntegrationSuite) TestIssue18515(c *C) { tk.MustExec("select /*+ TIDB_INLJ(t2) */ t1.a, t1.c, t2.a from t t1, t t2 where t1.c=t2.c;") } ->>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) func (s *testIntegrationSerialSuite) TestIssue17989(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index fdb627605226b..063c24a09384e 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -703,22 +703,6 @@ func (ds *DataSource) buildIndexMergeTableScan(prop *property.PhysicalProperty, physicalTableID: ds.physicalTableID, }.Init(ds.ctx, ds.blockOffset) ts.SetSchema(ds.schema.Clone()) -<<<<<<< HEAD - ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) -======= - if ts.HandleCols == nil { - handleCol := ds.getPKIsHandleCol() - if handleCol == nil { - handleCol, _ = ts.appendExtraHandleCol(ds) - } - ts.HandleCols = NewIntHandleCols(handleCol) - } - var err error - ts.HandleCols, err = ts.HandleCols.ResolveIndices(ts.schema) - if err != nil { - return nil, 0, err - } ->>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) if ts.Table.PKIsHandle { if pkColInfo := ts.Table.GetPkColInfo(); pkColInfo != nil { if ds.statisticTable.Columns[pkColInfo.ID] != nil { diff --git a/planner/core/initialize.go b/planner/core/initialize.go index 44e42823ace03..116478eb446f9 100644 --- a/planner/core/initialize.go +++ b/planner/core/initialize.go @@ -459,8 +459,6 @@ func (p BatchPointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInf return &p } -<<<<<<< HEAD -======= // Init initializes PointGetPlan. func (p PointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PointGetPlan { p.basePlan = newBasePlan(ctx, plancodec.TypePointGet, offset) @@ -469,15 +467,6 @@ func (p PointGetPlan) Init(ctx sessionctx.Context, stats *property.StatsInfo, of return &p } -func flattenTreePlan(plan PhysicalPlan, plans []PhysicalPlan) []PhysicalPlan { - plans = append(plans, plan) - for _, child := range plan.Children() { - plans = flattenTreePlan(child, plans) - } - return plans -} - ->>>>>>> 977449f... planner: fix a bug that can't find column in indexLookupJoin with virtual generated column (#18516) // flattenPushDownPlan converts a plan tree to a list, whose head is the leaf node like table scan. func flattenPushDownPlan(p PhysicalPlan) []PhysicalPlan { plans := make([]PhysicalPlan, 0, 5) diff --git a/planner/core/task.go b/planner/core/task.go index 045faa2985ceb..975314d905e0e 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -651,12 +651,7 @@ func finishCopTask(ctx sessionctx.Context, task task) task { tp := t.tablePlan for len(tp.Children()) > 0 { - if len(tp.Children()) == 1 { - tp = tp.Children()[0] - } else { - join := tp.(*PhysicalBroadCastJoin) - tp = join.children[1-join.InnerChildIdx] - } + tp = tp.Children()[0] } ts := tp.(*PhysicalTableScan) ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns)