Skip to content

Commit ccdcd19

Browse files
committed
make_restrictinfo() failed to attach the specified required_relids to
its result when the clause was an OR clause. Brain fade exposed by example from Sebastian BÎck.
1 parent 01798a0 commit ccdcd19

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/backend/optimizer/util/restrictinfo.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.42 2005/11/14 23:54:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.43 2005/11/16 17:08:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,7 +29,8 @@ static RestrictInfo *make_restrictinfo_internal(Expr *clause,
2929
Relids required_relids);
3030
static Expr *make_sub_restrictinfos(Expr *clause,
3131
bool is_pushed_down,
32-
bool outerjoin_delayed);
32+
bool outerjoin_delayed,
33+
Relids required_relids);
3334
static RestrictInfo *join_clause_is_redundant(PlannerInfo *root,
3435
RestrictInfo *rinfo,
3536
List *reference_list,
@@ -62,7 +63,8 @@ make_restrictinfo(Expr *clause,
6263
if (or_clause((Node *) clause))
6364
return (RestrictInfo *) make_sub_restrictinfos(clause,
6465
is_pushed_down,
65-
outerjoin_delayed);
66+
outerjoin_delayed,
67+
required_relids);
6668

6769
/* Shouldn't be an AND clause, else AND/OR flattening messed up */
6870
Assert(!and_clause((Node *) clause));
@@ -312,10 +314,15 @@ make_restrictinfo_internal(Expr *clause, Expr *orclause,
312314
* This may seem odd but it is closely related to the fact that we use
313315
* implicit-AND lists at top level of RestrictInfo lists. Only ORs and
314316
* simple clauses are valid RestrictInfos.
317+
*
318+
* The given required_relids are attached to our top-level output,
319+
* but any OR-clause constituents are allowed to default to just the
320+
* contained rels.
315321
*/
316322
static Expr *
317323
make_sub_restrictinfos(Expr *clause,
318-
bool is_pushed_down, bool outerjoin_delayed)
324+
bool is_pushed_down, bool outerjoin_delayed,
325+
Relids required_relids)
319326
{
320327
if (or_clause((Node *) clause))
321328
{
@@ -326,12 +333,13 @@ make_sub_restrictinfos(Expr *clause,
326333
orlist = lappend(orlist,
327334
make_sub_restrictinfos(lfirst(temp),
328335
is_pushed_down,
329-
outerjoin_delayed));
336+
outerjoin_delayed,
337+
NULL));
330338
return (Expr *) make_restrictinfo_internal(clause,
331339
make_orclause(orlist),
332340
is_pushed_down,
333341
outerjoin_delayed,
334-
NULL);
342+
required_relids);
335343
}
336344
else if (and_clause((Node *) clause))
337345
{
@@ -342,15 +350,16 @@ make_sub_restrictinfos(Expr *clause,
342350
andlist = lappend(andlist,
343351
make_sub_restrictinfos(lfirst(temp),
344352
is_pushed_down,
345-
outerjoin_delayed));
353+
outerjoin_delayed,
354+
required_relids));
346355
return make_andclause(andlist);
347356
}
348357
else
349358
return (Expr *) make_restrictinfo_internal(clause,
350359
NULL,
351360
is_pushed_down,
352361
outerjoin_delayed,
353-
NULL);
362+
required_relids);
354363
}
355364

356365
/*

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