Skip to content

Commit

Permalink
This is an automated cherry-pick of #55447
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
hawkingrei authored and ti-chi-bot committed Aug 19, 2024
1 parent 509f9dd commit d06884c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions executor/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3270,3 +3270,12 @@ func TestAnalyzeColumnsSkipMVIndexJsonCol(t *testing.T) {
require.True(t, stats.Indices[tblInfo.Indices[0].ID].IsStatsInitialized())
require.False(t, stats.Indices[tblInfo.Indices[1].ID].IsStatsInitialized())
}

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")
}
37 changes: 37 additions & 0 deletions pkg/executor/test/analyzetest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "analyzetest_test",
timeout = "short",
srcs = [
"analyze_bench_test.go",
"analyze_test.go",
"main_test.go",
],
flaky = True,
shard_count = 49,
deps = [
"//pkg/config",
"//pkg/domain",
"//pkg/domain/infosync",
"//pkg/errno",
"//pkg/executor",
"//pkg/infoschema",
"//pkg/kv",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
"//pkg/planner/core",
"//pkg/session",
"//pkg/sessionctx",
"//pkg/sessionctx/variable",
"//pkg/statistics",
"//pkg/testkit",
"//pkg/testkit/analyzehelper",
"//pkg/util/dbterror/exeerrors",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
)
10 changes: 10 additions & 0 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,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
}
for i := len(er.b.outerSchemas) - 1; i >= 0; i-- {
outerSchema, outerName := er.b.outerSchemas[i], er.b.outerNames[i]
Expand Down

0 comments on commit d06884c

Please sign in to comment.