From 57576eb816526333248da189bf19a45a9b22478b Mon Sep 17 00:00:00 2001 From: wjHuang Date: Tue, 20 Jul 2021 14:55:34 +0800 Subject: [PATCH] expression: fix output name for hidden column (#26354) --- cmd/explaintest/r/explain_generate_column_substitute.result | 6 +++--- ddl/db_integration_test.go | 5 +++++ expression/column.go | 4 ++++ planner/core/logical_plan_builder.go | 1 - planner/core/rule_partition_processor.go | 1 - 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/explaintest/r/explain_generate_column_substitute.result b/cmd/explaintest/r/explain_generate_column_substitute.result index 57b2654d5f91e..70cac7f655d25 100644 --- a/cmd/explaintest/r/explain_generate_column_substitute.result +++ b/cmd/explaintest/r/explain_generate_column_substitute.result @@ -261,7 +261,7 @@ a b c e desc select * from t order by a+1; id estRows task access object operator info Projection_5 10000.00 root test.t.a, test.t.b, test.t.c, test.t.e -└─Projection_13 10000.00 root test.t.a, test.t.b, test.t.c, test.t.e, EMPTY_NAME +└─Projection_13 10000.00 root test.t.a, test.t.b, test.t.c, test.t.e, plus(test.t.a, 1) └─IndexLookUp_12 10000.00 root ├─IndexFullScan_10(Build) 10000.00 cop[tikv] table:t, index:expr_idx_c(`a` + 1) keep order:true, stats:pseudo └─TableRowIDScan_11(Probe) 10000.00 cop[tikv] table:t keep order:false, stats:pseudo @@ -432,12 +432,12 @@ Projection 0.00 root test.t.a, test.t.b └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false desc format = 'brief' select count(upper(b)) from t group by upper(b); id estRows task access object operator info -StreamAgg 4.80 root group by:EMPTY_NAME, funcs:count(EMPTY_NAME)->Column#7 +StreamAgg 4.80 root group by:upper(test.t.b), funcs:count(upper(test.t.b))->Column#7 └─IndexReader 6.00 root index:IndexFullScan └─IndexFullScan 6.00 cop[tikv] table:t, index:expression_index_2(upper(`b`)) keep order:true desc format = 'brief' select max(upper(b)) from t group by upper(b); id estRows task access object operator info -StreamAgg 4.80 root group by:EMPTY_NAME, funcs:max(EMPTY_NAME)->Column#7 +StreamAgg 4.80 root group by:upper(test.t.b), funcs:max(upper(test.t.b))->Column#7 └─IndexReader 6.00 root index:IndexFullScan └─IndexFullScan 6.00 cop[tikv] table:t, index:expression_index_2(upper(`b`)) keep order:true desc format = 'brief' select count(upper(b)) from t use index() group by upper(b); diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 289254f3b2c34..0b13fe5971716 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2349,6 +2349,11 @@ func (s *testSerialDBSuite1) TestCreateExpressionIndexError(c *C) { tk.MustGetErrCode("create table t1 (col1 int, index ((concat(''))));", errno.ErrWrongKeyColumnFunctionalIndex) tk.MustGetErrCode("CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);", errno.ErrFunctionalIndexPrimaryKey) + + // For issue 26349 + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`))));") + tk.MustExec("update t t1 set t1.short_name='a' where t1.id='1';") } func (s *testSerialDBSuite1) TestAddExpressionIndexOnPartition(c *C) { diff --git a/expression/column.go b/expression/column.go index ebc0feaf93a06..e0f96408f864c 100644 --- a/expression/column.go +++ b/expression/column.go @@ -326,6 +326,10 @@ const columnPrefix = "Column#" // String implements Stringer interface. func (col *Column) String() string { + if col.IsHidden { + // A hidden column must be a virtual generated column, we should output its expression. + return col.VirtualExpr.String() + } if col.OrigName != "" { return col.OrigName } diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index bc808c1a96a16..66903f8bf3119 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -4025,7 +4025,6 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as ColName: col.Name, OrigTblName: tableInfo.Name, OrigColName: col.Name, - Hidden: col.Hidden, // For update statement and delete statement, internal version should see the special middle state column, while user doesn't. NotExplicitUsable: col.State != model.StatePublic, }) diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index 45119f0e551b9..f3338b165daed 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -306,7 +306,6 @@ func (s *partitionProcessor) reconstructTableColNames(ds *DataSource) ([]*types. ColName: colInfo.Name, OrigTblName: ds.tableInfo.Name, OrigColName: colInfo.Name, - Hidden: colInfo.Hidden, }) continue }