Skip to content

Commit

Permalink
expression: fix output name for hidden column (pingcap#26354)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Jul 20, 2021
1 parent 39a56e5 commit 57576eb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/explaintest/r/explain_generate_column_substitute.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions expression/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
1 change: 0 additions & 1 deletion planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 57576eb

Please sign in to comment.