aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-06-03 19:12:30 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-06-03 19:12:30 -0400
commitc82037e372394ee046e278887c8f938591ca7406 (patch)
tree42cb1238dba75eda75e986062bda5cbbabb570d9 /src
parent8355897ff296a3634f6b9c3da444622a02adda9c (diff)
downloadpostgresql-c82037e372394ee046e278887c8f938591ca7406.tar.gz
postgresql-c82037e372394ee046e278887c8f938591ca7406.zip
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 abb164655, but didn't think to search gram.y for problems of this ilk. Per gripe from Jean-Pierre Pelletier. Report: <fa0535ec6d6428cfec40c7e8a6d11156@mail.gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/gram.y20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index c46914d87bb..c554e634fbb 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -14512,10 +14512,16 @@ doNegateFloat(Value *v)
static Node *
makeAndExpr(Node *lexpr, Node *rexpr, int location)
{
+ Node *lexp = lexpr;
+
+ /* Look through AEXPR_PAREN nodes so they don't affect flattening */
+ while (IsA(lexp, A_Expr) &&
+ ((A_Expr *) lexp)->kind == AEXPR_PAREN)
+ lexp = ((A_Expr *) lexp)->lexpr;
/* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
- if (IsA(lexpr, BoolExpr))
+ if (IsA(lexp, BoolExpr))
{
- BoolExpr *blexpr = (BoolExpr *) lexpr;
+ BoolExpr *blexpr = (BoolExpr *) lexp;
if (blexpr->boolop == AND_EXPR)
{
@@ -14529,10 +14535,16 @@ makeAndExpr(Node *lexpr, Node *rexpr, int location)
static Node *
makeOrExpr(Node *lexpr, Node *rexpr, int location)
{
+ Node *lexp = lexpr;
+
+ /* Look through AEXPR_PAREN nodes so they don't affect flattening */
+ while (IsA(lexp, A_Expr) &&
+ ((A_Expr *) lexp)->kind == AEXPR_PAREN)
+ lexp = ((A_Expr *) lexp)->lexpr;
/* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
- if (IsA(lexpr, BoolExpr))
+ if (IsA(lexp, BoolExpr))
{
- BoolExpr *blexpr = (BoolExpr *) lexpr;
+ BoolExpr *blexpr = (BoolExpr *) lexp;
if (blexpr->boolop == OR_EXPR)
{