diff --git a/pkg/expression/column.go b/pkg/expression/column.go index af95e1efc313e..5920f6b70f20b 100644 --- a/pkg/expression/column.go +++ b/pkg/expression/column.go @@ -390,8 +390,8 @@ 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. + if col.IsHidden && col.VirtualExpr != nil { + // A hidden column without virtual expression indicates it's a stored type. return col.VirtualExpr.String() } if col.OrigName != "" { diff --git a/pkg/table/tables/tables_test.go b/pkg/table/tables/tables_test.go index 2deea74fc46c4..bd54bafbdac45 100644 --- a/pkg/table/tables/tables_test.go +++ b/pkg/table/tables/tables_test.go @@ -544,6 +544,7 @@ func TestHiddenColumn(t *testing.T) { tk.MustGetErrMsg("update t set a=1 where c=3 order by b;", "[planner:1054]Unknown column 'b' in 'order clause'") // `DELETE` statement + tk.MustQuery("trace plan delete from t;") tk.MustExec("delete from t;") tk.MustQuery("select count(*) from t;").Check(testkit.Rows("0")) tk.MustExec("insert into t values (1, 3, 5);")