From 0dc2524b371c6163bb04a3af1ee3bdbbc52d5d98 Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Thu, 28 Mar 2024 15:05:32 +0800 Subject: [PATCH] fix hidden column may do not have a virtual expression Signed-off-by: AilinKid <314806019@qq.com> --- pkg/expression/column.go | 4 ++-- pkg/table/tables/tables_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) 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);")