Skip to content

Commit a49147a

Browse files
committed
Fix an oversight in convert_EXISTS_sublink_to_join: we can't convert an
EXISTS that contains a WITH clause. This would usually lead to a "could not find CTE" error later in planning, because the WITH wouldn't get processed at all. Noted while playing with an example from Ken Marshall.
1 parent a0a7e63 commit a49147a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/optimizer/plan/subselect.c

Lines changed: 12 additions & 1 deletion
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.157 2010/01/02 16:57:47 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.158 2010/01/18 18:17:45 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1114,6 +1114,17 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
11141114

11151115
Assert(sublink->subLinkType == EXISTS_SUBLINK);
11161116

1117+
/*
1118+
* Can't flatten if it contains WITH. (We could arrange to pull up the
1119+
* WITH into the parent query's cteList, but that risks changing the
1120+
* semantics, since a WITH ought to be executed once per associated query
1121+
* call.) Note that convert_ANY_sublink_to_join doesn't have to reject
1122+
* this case, since it just produces a subquery RTE that doesn't have to
1123+
* get flattened into the parent query.
1124+
*/
1125+
if (subselect->cteList)
1126+
return NULL;
1127+
11171128
/*
11181129
* Copy the subquery so we can modify it safely (see comments in
11191130
* make_subplan).

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