7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -1148,10 +1148,14 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
1148
1148
* take steps to preserve AND/OR flatness of a qual. We assume the input
1149
1149
* has been AND/OR flattened and so we need no recursion here.
1150
1150
*
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.)
1155
1159
*/
1156
1160
if (and_clause (node ))
1157
1161
{
@@ -1174,14 +1178,14 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
1174
1178
return (Node * ) make_andclause (newargs );
1175
1179
}
1176
1180
1177
- /* otherwise not at qual top-level */
1178
- locContext .isTopQual = false;
1179
-
1180
1181
if (or_clause (node ))
1181
1182
{
1182
1183
List * newargs = NIL ;
1183
1184
ListCell * l ;
1184
1185
1186
+ /* Still at qual top-level */
1187
+ locContext .isTopQual = context -> isTopQual ;
1188
+
1185
1189
foreach (l , ((BoolExpr * ) node )-> args )
1186
1190
{
1187
1191
Node * newarg ;
@@ -1195,6 +1199,12 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
1195
1199
return (Node * ) make_orclause (newargs );
1196
1200
}
1197
1201
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
+
1198
1208
return expression_tree_mutator (node ,
1199
1209
process_sublinks_mutator ,
1200
1210
(void * ) & locContext );
0 commit comments