From ab2770058c319a2c93e7cd077dc2ed997cb4a5af Mon Sep 17 00:00:00 2001 From: teooooozhang Date: Thu, 9 Feb 2023 15:55:21 +0800 Subject: [PATCH] =?UTF-8?q?issue=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=AC=A6=E4=BC=98=E5=85=88=E7=BA=A7=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=89=B9=E5=AE=9A=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/gram.y | 39 ++++++++++++++------------- src/common/backend/parser/parser.cpp | 3 +++ src/test/regress/expected/boolean.out | 6 +++++ src/test/regress/sql/boolean.sql | 2 ++ 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index ac5ea6b18..b1994d5b6 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -940,6 +940,7 @@ static void setDelimiterName(core_yyscan_t yyscanner, char*input, VariableSetStm END_OF_INPUT END_OF_INPUT_COLON END_OF_PROC + NOT_IN /* Precedence: lowest to highest */ %nonassoc COMMENT @@ -960,7 +961,7 @@ static void setDelimiterName(core_yyscan_t yyscanner, char*input, VariableSetStm %nonassoc ESCAPE %nonassoc OVERLAPS %nonassoc BETWEEN -%nonassoc IN_P +%nonassoc IN_P NOT_IN %left POSTFIXOP /* dummy for postfix Op rules */ /* * To support target_el without AS, we must give IDENT an explicit priority @@ -1646,18 +1647,18 @@ CreateUserStmt: IsValidIdentUsername($3); n->role = $3; n->options = $6; - n->missing_ok = false; - $$ = (Node *)n; - u_sess->parser_cxt.isForbidTruncate = false; - } - | CREATE USER IF_P NOT EXISTS RoleId opt_with {u_sess->parser_cxt.isForbidTruncate = true;} OptRoleList - { - CreateRoleStmt *n = makeNode(CreateRoleStmt); - n->stmt_type = ROLESTMT_USER; - IsValidIdentUsername($6); - n->role = $6; - n->options = $9; - n->missing_ok = true; + n->missing_ok = false; + $$ = (Node *)n; + u_sess->parser_cxt.isForbidTruncate = false; + } + | CREATE USER IF_P NOT EXISTS RoleId opt_with {u_sess->parser_cxt.isForbidTruncate = true;} OptRoleList + { + CreateRoleStmt *n = makeNode(CreateRoleStmt); + n->stmt_type = ROLESTMT_USER; + IsValidIdentUsername($6); + n->role = $6; + n->options = $9; + n->missing_ok = true; $$ = (Node *)n; u_sess->parser_cxt.isForbidTruncate = false; } @@ -1850,7 +1851,7 @@ CreateGroupStmt: n->stmt_type = ROLESTMT_GROUP; n->role = $3; n->options = $5; - n->missing_ok = false; + n->missing_ok = false; $$ = (Node *)n; } ; @@ -23861,25 +23862,25 @@ a_expr: c_expr { $$ = $1; } $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2); } } - | a_expr NOT IN_P in_expr + | a_expr NOT_IN in_expr %prec NOT_IN { /* in_expr returns a SubLink or a list of a_exprs */ - if (IsA($4, SubLink)) + if (IsA($3, SubLink)) { /* generate NOT (foo = ANY (subquery)) */ /* Make an = ANY node */ - SubLink *n = (SubLink *) $4; + SubLink *n = (SubLink *) $3; n->subLinkType = ANY_SUBLINK; n->testexpr = $1; n->operName = list_make1(makeString("=")); - n->location = @3; + n->location = @2; /* Stick a NOT on top */ $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2); } else { /* generate scalar NOT IN expression */ - $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2); + $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $3, @2); } } | a_expr subquery_Op sub_type select_with_parens %prec Op diff --git a/src/common/backend/parser/parser.cpp b/src/common/backend/parser/parser.cpp index 2ddbfa28c..61432d6d0 100644 --- a/src/common/backend/parser/parser.cpp +++ b/src/common/backend/parser/parser.cpp @@ -231,6 +231,9 @@ int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner) case ENFORCED: cur_token = NOT_ENFORCED; break; + case IN_P: + cur_token = NOT_IN; + break; default: /* save the lookahead token for next time */ SET_LOOKAHEAD_TOKEN(); diff --git a/src/test/regress/expected/boolean.out b/src/test/regress/expected/boolean.out index da7bc2f33..856a6b5fb 100644 --- a/src/test/regress/expected/boolean.out +++ b/src/test/regress/expected/boolean.out @@ -470,6 +470,12 @@ SELECT 1-2::bool; 0 (1 row) +select true >= 'ss' not in (md5('ss')); + ?column? +---------- + t +(1 row) + -- -- Clean up -- Many tables are retained by the regression test, but these do not seem diff --git a/src/test/regress/sql/boolean.sql b/src/test/regress/sql/boolean.sql index 4be3f3f24..106bb3b19 100644 --- a/src/test/regress/sql/boolean.sql +++ b/src/test/regress/sql/boolean.sql @@ -206,6 +206,8 @@ SELECT -2::bool; SELECT 1-2::bool; +select true >= 'ss' not in (md5('ss')); + -- -- Clean up -- Many tables are retained by the regression test, but these do not seem