From 9cf30372a03668971fb80dd99d303e4dab30d0d0 Mon Sep 17 00:00:00 2001 From: Jun-Seok Heo Date: Thu, 8 Nov 2018 15:20:00 +0900 Subject: [PATCH] [parser] Revert "parser,ast: fix the TiDB issue #8153 (#20)" (#24) --- parser/ast/expressions.go | 9 +-------- parser/parser.go | 10 ++++++---- parser/parser.y | 12 +++++++----- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/parser/ast/expressions.go b/parser/ast/expressions.go index c3d38dcf7bcef..e81f878760b8d 100644 --- a/parser/ast/expressions.go +++ b/parser/ast/expressions.go @@ -699,7 +699,7 @@ func (n *ParenthesesExpr) Accept(v Visitor) (Node, bool) { type PositionExpr struct { exprNode // N is the position, started from 1 now. - N ExprNode + N int // Refer is the result field the position refers to. Refer *ResultField } @@ -716,13 +716,6 @@ func (n *PositionExpr) Accept(v Visitor) (Node, bool) { return v.Leave(newNode) } n = newNode.(*PositionExpr) - if n.N != nil { - node, ok := n.N.Accept(v) - if !ok { - return n, false - } - n.N = node.(ExprNode) - } return v.Leave(n) } diff --git a/parser/parser.go b/parser/parser.go index edbae2a25e0a1..0e57c82e4a53f 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -8408,10 +8408,12 @@ yynewstate: case 607: { expr := yyS[yypt-1].expr - if valueExpr, ok := expr.(ast.ValueExpr); ok { - expr = &ast.PositionExpr{N: valueExpr} - } else if paramExpr, ok := expr.(ast.ParamMarkerExpr); ok { - expr = &ast.PositionExpr{N: paramExpr} + valueExpr, ok := expr.(ast.ValueExpr) + if ok { + position, isPosition := valueExpr.GetValue().(int64) + if isPosition { + expr = &ast.PositionExpr{N: int(position)} + } } parser.yyVAL.item = &ast.ByItem{Expr: expr, Desc: yyS[yypt-0].item.(bool)} } diff --git a/parser/parser.y b/parser/parser.y index b1be8c27dc6aa..229620ff2c167 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -3188,11 +3188,13 @@ ByItem: Expression Order { expr := $1 - if valueExpr, ok := expr.(ast.ValueExpr); ok { - expr = &ast.PositionExpr{N: valueExpr} - } else if paramExpr, ok := expr.(ast.ParamMarkerExpr); ok { - expr = &ast.PositionExpr{N: paramExpr} - } + valueExpr, ok := expr.(ast.ValueExpr) + if ok { + position, isPosition := valueExpr.GetValue().(int64) + if isPosition { + expr = &ast.PositionExpr{N: int(position)} + } + } $$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)} }