Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 05104f6

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 d50183c commit 05104f6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/backend/parser/gram.y

+16-4
Original file line numberDiff line numberDiff line change
@@ -14643,10 +14643,16 @@ doNegateFloat(Value *v)
1464314643
static Node *
1464414644
makeAndExpr(Node *lexpr, Node *rexpr, int location)
1464514645
{
14646+
Node *lexp = lexpr;
14647+
14648+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14649+
while (IsA(lexp, A_Expr) &&
14650+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14651+
lexp = ((A_Expr *) lexp)->lexpr;
1464614652
/* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
14647-
if (IsA(lexpr, BoolExpr))
14653+
if (IsA(lexp, BoolExpr))
1464814654
{
14649-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14655+
BoolExpr *blexpr = (BoolExpr *) lexp;
1465014656

1465114657
if (blexpr->boolop == AND_EXPR)
1465214658
{
@@ -14660,10 +14666,16 @@ makeAndExpr(Node *lexpr, Node *rexpr, int location)
1466014666
static Node *
1466114667
makeOrExpr(Node *lexpr, Node *rexpr, int location)
1466214668
{
14669+
Node *lexp = lexpr;
14670+
14671+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14672+
while (IsA(lexp, A_Expr) &&
14673+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14674+
lexp = ((A_Expr *) lexp)->lexpr;
1466314675
/* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
14664-
if (IsA(lexpr, BoolExpr))
14676+
if (IsA(lexp, BoolExpr))
1466514677
{
14666-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14678+
BoolExpr *blexpr = (BoolExpr *) lexp;
1466714679

1466814680
if (blexpr->boolop == OR_EXPR)
1466914681
{

0 commit comments

Comments
 (0)