diff --git a/ast/expressions.go b/ast/expressions.go index 440a89e06fdd6..e359b121c7444 100644 --- a/ast/expressions.go +++ b/ast/expressions.go @@ -927,7 +927,9 @@ func (n *ValuesExpr) Accept(v Visitor) (Node, bool) { if !ok { return n, false } - n.Column = node.(*ColumnNameExpr) + // `node` may be *ast.ValueExpr, to avoid panic, we write `ok` but do not use + // it. + n.Column, ok = node.(*ColumnNameExpr) return v.Leave(n) } diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 90280d4851757..cc2d08a28d575 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1181,6 +1181,10 @@ func (g *gbyResolver) Leave(inNode ast.Node) (ast.Node, bool) { return inNode, false } return ret, true + case *ast.ValuesExpr: + if v.Column == nil { + g.err = ErrUnknownColumn.GenWithStackByArgs("", "VALUES() function") + } } return inNode, true } diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 91d093b7fa79b..88a8aedb41057 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -1995,6 +1995,7 @@ func (s *testPlanSuite) TestNameResolver(c *C) { {"select a from t group by t11.c1", "[planner:1054]Unknown column 't11.c1' in 'group statement'"}, {"delete a from (select * from t ) as a, t", "[planner:1288]The target table a of the DELETE is not updatable"}, {"delete b from (select * from t ) as a, t", "[planner:1109]Unknown table 'b' in MULTI DELETE"}, + {"select '' as fakeCol from t group by values(fakeCol)", "[planner:1054]Unknown column '' in 'VALUES() function'"}, {"update t, (select * from t) as b set b.a = t.a", "[planner:1288]The target table b of the UPDATE is not updatable"}, }