From 1bdf124b94af3c24d3c3083c820804274df8262b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 14 Nov 2005 23:54:23 +0000 Subject: =?UTF-8?q?Restore=20the=20former=20RestrictInfo=20field=20valid?= =?UTF-8?q?=5Feverywhere=20(but=20invert=20the=20flag=20sense=20and=20rena?= =?UTF-8?q?me=20to=20"outerjoin=5Fdelayed"=20to=20more=20clearly=20reflect?= =?UTF-8?q?=20what=20it=20means).=20=20I=20had=20decided=20that=20it=20was?= =?UTF-8?q?=20redundant=20in=208.1,=20but=20the=20folly=20of=20this=20is?= =?UTF-8?q?=20exposed=20by=20a=20bug=20report=20from=20Sebastian=20B=C3=B6?= =?UTF-8?q?ck.=20=20The=20place=20where=20it's=20needed=20is=20to=20preven?= =?UTF-8?q?t=20orindxpath.c=20from=20cherry-picking=20arms=20of=20an=20out?= =?UTF-8?q?er-join=20OR=20clause=20to=20form=20a=20relation=20restriction?= =?UTF-8?q?=20that=20isn't=20actually=20legal=20to=20push=20down=20to=20th?= =?UTF-8?q?e=20relation=20scan=20level.=20=20There=20may=20be=20some=20leg?= =?UTF-8?q?al=20cases=20that=20this=20forbids=20optimizing,=20but=20we'd?= =?UTF-8?q?=20need=20much=20closer=20analysis=20to=20determine=20it.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/optimizer/util/restrictinfo.c | 42 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/backend/optimizer/util/restrictinfo.c') diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c index d277cac7351..96c207c9350 100644 --- a/src/backend/optimizer/util/restrictinfo.c +++ b/src/backend/optimizer/util/restrictinfo.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.41 2005/10/15 02:49:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.42 2005/11/14 23:54:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,9 +25,11 @@ static RestrictInfo *make_restrictinfo_internal(Expr *clause, Expr *orclause, bool is_pushed_down, + bool outerjoin_delayed, Relids required_relids); static Expr *make_sub_restrictinfos(Expr *clause, - bool is_pushed_down); + bool is_pushed_down, + bool outerjoin_delayed); static RestrictInfo *join_clause_is_redundant(PlannerInfo *root, RestrictInfo *rinfo, List *reference_list, @@ -39,8 +41,8 @@ static RestrictInfo *join_clause_is_redundant(PlannerInfo *root, * * Build a RestrictInfo node containing the given subexpression. * - * The is_pushed_down flag must be supplied by the caller. - * required_relids can be NULL, in which case it defaults to the + * The is_pushed_down and outerjoin_delayed flags must be supplied by the + * caller. required_relids can be NULL, in which case it defaults to the * actual clause contents (i.e., clause_relids). * * We initialize fields that depend only on the given subexpression, leaving @@ -48,19 +50,25 @@ static RestrictInfo *join_clause_is_redundant(PlannerInfo *root, * later. */ RestrictInfo * -make_restrictinfo(Expr *clause, bool is_pushed_down, Relids required_relids) +make_restrictinfo(Expr *clause, + bool is_pushed_down, + bool outerjoin_delayed, + Relids required_relids) { /* * If it's an OR clause, build a modified copy with RestrictInfos inserted * above each subclause of the top-level AND/OR structure. */ if (or_clause((Node *) clause)) - return (RestrictInfo *) make_sub_restrictinfos(clause, is_pushed_down); + return (RestrictInfo *) make_sub_restrictinfos(clause, + is_pushed_down, + outerjoin_delayed); /* Shouldn't be an AND clause, else AND/OR flattening messed up */ Assert(!and_clause((Node *) clause)); - return make_restrictinfo_internal(clause, NULL, is_pushed_down, + return make_restrictinfo_internal(clause, NULL, + is_pushed_down, outerjoin_delayed, required_relids); } @@ -74,6 +82,9 @@ make_restrictinfo(Expr *clause, bool is_pushed_down, Relids required_relids) * The result is a List (effectively, implicit-AND representation) of * RestrictInfos. * + * The caller must pass is_pushed_down, but we assume outerjoin_delayed + * is false (no such qual should ever get into a bitmapqual). + * * If include_predicates is true, we add any partial index predicates to * the explicit index quals. When this is not true, we return a condition * that might be weaker than the actual scan represents. @@ -169,6 +180,7 @@ make_restrictinfo_from_bitmapqual(Path *bitmapqual, list_make1(make_restrictinfo_internal(make_orclause(withoutris), make_orclause(withris), is_pushed_down, + false, NULL)); } } @@ -193,6 +205,7 @@ make_restrictinfo_from_bitmapqual(Path *bitmapqual, result = lappend(result, make_restrictinfo(pred, is_pushed_down, + false, NULL)); } } @@ -213,13 +226,15 @@ make_restrictinfo_from_bitmapqual(Path *bitmapqual, */ static RestrictInfo * make_restrictinfo_internal(Expr *clause, Expr *orclause, - bool is_pushed_down, Relids required_relids) + bool is_pushed_down, bool outerjoin_delayed, + Relids required_relids) { RestrictInfo *restrictinfo = makeNode(RestrictInfo); restrictinfo->clause = clause; restrictinfo->orclause = orclause; restrictinfo->is_pushed_down = is_pushed_down; + restrictinfo->outerjoin_delayed = outerjoin_delayed; restrictinfo->can_join = false; /* may get set below */ /* @@ -299,7 +314,8 @@ make_restrictinfo_internal(Expr *clause, Expr *orclause, * simple clauses are valid RestrictInfos. */ static Expr * -make_sub_restrictinfos(Expr *clause, bool is_pushed_down) +make_sub_restrictinfos(Expr *clause, + bool is_pushed_down, bool outerjoin_delayed) { if (or_clause((Node *) clause)) { @@ -309,10 +325,12 @@ make_sub_restrictinfos(Expr *clause, bool is_pushed_down) foreach(temp, ((BoolExpr *) clause)->args) orlist = lappend(orlist, make_sub_restrictinfos(lfirst(temp), - is_pushed_down)); + is_pushed_down, + outerjoin_delayed)); return (Expr *) make_restrictinfo_internal(clause, make_orclause(orlist), is_pushed_down, + outerjoin_delayed, NULL); } else if (and_clause((Node *) clause)) @@ -323,13 +341,15 @@ make_sub_restrictinfos(Expr *clause, bool is_pushed_down) foreach(temp, ((BoolExpr *) clause)->args) andlist = lappend(andlist, make_sub_restrictinfos(lfirst(temp), - is_pushed_down)); + is_pushed_down, + outerjoin_delayed)); return make_andclause(andlist); } else return (Expr *) make_restrictinfo_internal(clause, NULL, is_pushed_down, + outerjoin_delayed, NULL); } -- cgit v1.2.3