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,
2929Relids required_relids );
3030static Expr * make_sub_restrictinfos (Expr * clause ,
3131bool is_pushed_down ,
32- bool outerjoin_delayed );
32+ bool outerjoin_delayed ,
33+ Relids required_relids );
3334static RestrictInfo * join_clause_is_redundant (PlannerInfo * root ,
3435RestrictInfo * rinfo ,
3536List * reference_list ,
@@ -62,7 +63,8 @@ make_restrictinfo(Expr *clause,
6263if (or_clause ((Node * )clause ))
6364return (RestrictInfo * )make_sub_restrictinfos (clause ,
6465is_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 */
6870Assert (!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 */
316322static Expr *
317323make_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{
320327if (or_clause ((Node * )clause ))
321328{
@@ -326,12 +333,13 @@ make_sub_restrictinfos(Expr *clause,
326333orlist = lappend (orlist ,
327334make_sub_restrictinfos (lfirst (temp ),
328335is_pushed_down ,
329- outerjoin_delayed ));
336+ outerjoin_delayed ,
337+ NULL ));
330338return (Expr * )make_restrictinfo_internal (clause ,
331339make_orclause (orlist ),
332340is_pushed_down ,
333341outerjoin_delayed ,
334- NULL );
342+ required_relids );
335343}
336344else if (and_clause ((Node * )clause ))
337345{
@@ -342,15 +350,16 @@ make_sub_restrictinfos(Expr *clause,
342350andlist = lappend (andlist ,
343351make_sub_restrictinfos (lfirst (temp ),
344352is_pushed_down ,
345- outerjoin_delayed ));
353+ outerjoin_delayed ,
354+ required_relids ));
346355return make_andclause (andlist );
347356}
348357else
349358return (Expr * )make_restrictinfo_internal (clause ,
350359NULL ,
351360is_pushed_down ,
352361outerjoin_delayed ,
353- NULL );
362+ required_relids );
354363}
355364
356365/*