Skip to content

Commit c82037e

Browse files
committed
Fix grammar's AND/OR flattening to work with operator_precedence_warning.
It'd be good for "(x AND y) AND z" to produce a three-child AND node whether or not operator_precedence_warning is on, but that failed to happen when it's on because makeAndExpr() didn't look through the added AEXPR_PAREN node. This has no effect on generated plans because prepqual.c would flatten the AND nest anyway; but it does affect the number of parens printed in ruleutils.c, for example. I'd already fixed some similar hazards in parse_expr.c in commit abb1646, but didn't think to search gram.y for problems of this ilk. Per gripe from Jean-Pierre Pelletier. Report: <fa0535ec6d6428cfec40c7e8a6d11156@mail.gmail.com>
1 parent 8355897 commit c82037e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/backend/parser/gram.y

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14512,10 +14512,16 @@ doNegateFloat(Value *v)
1451214512
static Node *
1451314513
makeAndExpr(Node *lexpr, Node *rexpr, int location)
1451414514
{
14515+
Node *lexp = lexpr;
14516+
14517+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14518+
while (IsA(lexp, A_Expr) &&
14519+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14520+
lexp = ((A_Expr *) lexp)->lexpr;
1451514521
/* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
14516-
if (IsA(lexpr, BoolExpr))
14522+
if (IsA(lexp, BoolExpr))
1451714523
{
14518-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14524+
BoolExpr *blexpr = (BoolExpr *) lexp;
1451914525

1452014526
if (blexpr->boolop == AND_EXPR)
1452114527
{
@@ -14529,10 +14535,16 @@ makeAndExpr(Node *lexpr, Node *rexpr, int location)
1452914535
static Node *
1453014536
makeOrExpr(Node *lexpr, Node *rexpr, int location)
1453114537
{
14538+
Node *lexp = lexpr;
14539+
14540+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14541+
while (IsA(lexp, A_Expr) &&
14542+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14543+
lexp = ((A_Expr *) lexp)->lexpr;
1453214544
/* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
14533-
if (IsA(lexpr, BoolExpr))
14545+
if (IsA(lexp, BoolExpr))
1453414546
{
14535-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14547+
BoolExpr *blexpr = (BoolExpr *) lexp;
1453614548

1453714549
if (blexpr->boolop == OR_EXPR)
1453814550
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy