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

Commit cc0dd43

Browse files
committed
Marginal improvement in sublink planning: allow unknownEqFalse optimization
to be used for SubLinks that are underneath a top-level OR clause. Just as at the very top level of WHERE, it's not necessary to be accurate about whether the sublink returns FALSE or NULL, because either result has the same impact on whether the WHERE will succeed.
1 parent 3c35de8 commit cc0dd43

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/backend/optimizer/plan/subselect.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.136 2008/08/20 15:49:30 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.137 2008/08/20 19:58:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1148,10 +1148,14 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
11481148
* take steps to preserve AND/OR flatness of a qual. We assume the input
11491149
* has been AND/OR flattened and so we need no recursion here.
11501150
*
1151-
* If we recurse down through anything other than an AND node, we are
1152-
* definitely not at top qual level anymore. (Due to the coding here, we
1153-
* will not get called on the List subnodes of an AND, so no check is
1154-
* needed for List.)
1151+
* (Due to the coding here, we will not get called on the List subnodes of
1152+
* an AND; and the input is *not* yet in implicit-AND format. So no check
1153+
* is needed for a bare List.)
1154+
*
1155+
* Anywhere within the top-level AND/OR clause structure, we can tell
1156+
* make_subplan() that NULL and FALSE are interchangeable. So isTopQual
1157+
* propagates down in both cases. (Note that this is unlike the meaning
1158+
* of "top level qual" used in most other places in Postgres.)
11551159
*/
11561160
if (and_clause(node))
11571161
{
@@ -1174,14 +1178,14 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
11741178
return (Node *) make_andclause(newargs);
11751179
}
11761180

1177-
/* otherwise not at qual top-level */
1178-
locContext.isTopQual = false;
1179-
11801181
if (or_clause(node))
11811182
{
11821183
List *newargs = NIL;
11831184
ListCell *l;
11841185

1186+
/* Still at qual top-level */
1187+
locContext.isTopQual = context->isTopQual;
1188+
11851189
foreach(l, ((BoolExpr *) node)->args)
11861190
{
11871191
Node *newarg;
@@ -1195,6 +1199,12 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
11951199
return (Node *) make_orclause(newargs);
11961200
}
11971201

1202+
/*
1203+
* If we recurse down through anything other than an AND or OR node,
1204+
* we are definitely not at top qual level anymore.
1205+
*/
1206+
locContext.isTopQual = false;
1207+
11981208
return expression_tree_mutator(node,
11991209
process_sublinks_mutator,
12001210
(void *) &locContext);

0 commit comments

Comments
 (0)