diff --git a/pkg/executor/test/analyzetest/BUILD.bazel b/pkg/executor/test/analyzetest/BUILD.bazel index 58ef0f964e7b3..7a3cc9e4ce316 100644 --- a/pkg/executor/test/analyzetest/BUILD.bazel +++ b/pkg/executor/test/analyzetest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 48, + shard_count = 49, deps = [ "//pkg/config", "//pkg/domain", diff --git a/pkg/executor/test/analyzetest/analyze_test.go b/pkg/executor/test/analyzetest/analyze_test.go index 90fbcff71bc9f..1fa101b4b55cc 100644 --- a/pkg/executor/test/analyzetest/analyze_test.go +++ b/pkg/executor/test/analyzetest/analyze_test.go @@ -3127,3 +3127,12 @@ func TestAnalyzePartitionVerify(t *testing.T) { } } } + +func TestIssue55438(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE t0(c0 NUMERIC , c1 BIGINT UNSIGNED AS ((CASE 0 WHEN false THEN 1358571571 ELSE TRIM(c0) END )));") + tk.MustExec("CREATE INDEX i0 ON t0(c1);") + tk.MustExec("analyze table t0") +} diff --git a/pkg/planner/core/expression_rewriter.go b/pkg/planner/core/expression_rewriter.go index 10386cd2df1dc..78867a88bfd29 100644 --- a/pkg/planner/core/expression_rewriter.go +++ b/pkg/planner/core/expression_rewriter.go @@ -2396,6 +2396,16 @@ func (er *expressionRewriter) toColumn(v *ast.ColumnName) { } er.ctxStackAppend(column, er.names[idx]) return + } else if er.planCtx == nil && er.sourceTable != nil && + (v.Table.L == "" || er.sourceTable.Name.L == v.Table.L) { + colInfo := er.sourceTable.FindPublicColumnByName(v.Name.L) + if colInfo == nil || colInfo.Hidden { + er.err = plannererrors.ErrUnknownColumn.GenWithStackByArgs(v.Name, clauseMsg[er.clause()]) + return + } + er.ctxStackAppend(&expression.Column{RetType: &colInfo.FieldType, ID: colInfo.ID, UniqueID: colInfo.ID}, + &types.FieldName{ColName: v.Name}) + return } planCtx := er.planCtx