Skip to content

Commit

Permalink
*: fix cannot get column info from generate column (#55447) (#55510)
Browse files Browse the repository at this point in the history
close #55438
  • Loading branch information
ti-chi-bot authored Aug 20, 2024
1 parent 23c1352 commit 4b5e057
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/executor/test/analyzetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 48,
shard_count = 49,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
9 changes: 9 additions & 0 deletions pkg/executor/test/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
10 changes: 10 additions & 0 deletions pkg/planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b5e057

Please sign in to comment.