Skip to content

Commit cc5e80b

Browse files
committed
Teach planner about some cases where a restriction clause can be
propagated inside an outer join. In particular, given LEFT JOIN ON (A = B) WHERE A = constant, we cannot conclude that B = constant at the top level (B might be null instead), but we can nonetheless put a restriction B = constant into the quals for B's relation, since no inner-side rows not meeting that condition can contribute to the final result. Similarly, given FULL JOIN USING (J) WHERE J = constant, we can't directly conclude that either input J variable = constant, but it's OK to push such quals into each input rel. Per recent gripe from Kim Bisgaard. Along the way, remove 'valid_everywhere' flag from RestrictInfo, as on closer analysis it was not being used for anything, and was defined backwards anyway.
1 parent ea1e2b9 commit cc5e80b

File tree

13 files changed

+424
-114
lines changed

13 files changed

+424
-114
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.310 2005/06/28 05:08:56 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.311 2005/07/02 23:00:39 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1249,7 +1249,6 @@ _copyRestrictInfo(RestrictInfo *from)
12491249

12501250
COPY_NODE_FIELD(clause);
12511251
COPY_SCALAR_FIELD(is_pushed_down);
1252-
COPY_SCALAR_FIELD(valid_everywhere);
12531252
COPY_SCALAR_FIELD(can_join);
12541253
COPY_BITMAPSET_FIELD(clause_relids);
12551254
COPY_BITMAPSET_FIELD(required_relids);

src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.247 2005/06/28 05:08:57 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.248 2005/07/02 23:00:39 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -603,7 +603,6 @@ _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
603603
{
604604
COMPARE_NODE_FIELD(clause);
605605
COMPARE_SCALAR_FIELD(is_pushed_down);
606-
COMPARE_SCALAR_FIELD(valid_everywhere);
607606
COMPARE_BITMAPSET_FIELD(required_relids);
608607

609608
/*

src/backend/nodes/outfuncs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.257 2005/06/28 05:08:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.258 2005/07/02 23:00:39 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1164,9 +1164,13 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
11641164
WRITE_NODE_FIELD(parse);
11651165
WRITE_NODE_FIELD(join_rel_list);
11661166
WRITE_NODE_FIELD(equi_key_list);
1167+
WRITE_NODE_FIELD(left_join_clauses);
1168+
WRITE_NODE_FIELD(right_join_clauses);
1169+
WRITE_NODE_FIELD(full_join_clauses);
11671170
WRITE_NODE_FIELD(in_info_list);
11681171
WRITE_NODE_FIELD(query_pathkeys);
11691172
WRITE_BOOL_FIELD(hasJoinRTEs);
1173+
WRITE_BOOL_FIELD(hasOuterJoins);
11701174
WRITE_BOOL_FIELD(hasHavingQual);
11711175
}
11721176

@@ -1234,7 +1238,6 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
12341238
/* NB: this isn't a complete set of fields */
12351239
WRITE_NODE_FIELD(clause);
12361240
WRITE_BOOL_FIELD(is_pushed_down);
1237-
WRITE_BOOL_FIELD(valid_everywhere);
12381241
WRITE_BOOL_FIELD(can_join);
12391242
WRITE_BITMAPSET_FIELD(clause_relids);
12401243
WRITE_BITMAPSET_FIELD(required_relids);

src/backend/optimizer/path/indxpath.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.185 2005/06/14 04:04:30 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.186 2005/07/02 23:00:40 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1882,7 +1882,7 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
18821882
{
18831883
resultquals = lappend(resultquals,
18841884
make_restrictinfo(boolqual,
1885-
true, true,
1885+
true,
18861886
NULL));
18871887
continue;
18881888
}
@@ -2132,7 +2132,7 @@ prefix_quals(Node *leftop, Oid opclass,
21322132
elog(ERROR, "no = operator for opclass %u", opclass);
21332133
expr = make_opclause(oproid, BOOLOID, false,
21342134
(Expr *) leftop, (Expr *) prefix_const);
2135-
result = list_make1(make_restrictinfo(expr, true, true, NULL));
2135+
result = list_make1(make_restrictinfo(expr, true, NULL));
21362136
return result;
21372137
}
21382138

@@ -2147,7 +2147,7 @@ prefix_quals(Node *leftop, Oid opclass,
21472147
elog(ERROR, "no >= operator for opclass %u", opclass);
21482148
expr = make_opclause(oproid, BOOLOID, false,
21492149
(Expr *) leftop, (Expr *) prefix_const);
2150-
result = list_make1(make_restrictinfo(expr, true, true, NULL));
2150+
result = list_make1(make_restrictinfo(expr, true, NULL));
21512151

21522152
/*-------
21532153
* If we can create a string larger than the prefix, we can say
@@ -2163,7 +2163,7 @@ prefix_quals(Node *leftop, Oid opclass,
21632163
elog(ERROR, "no < operator for opclass %u", opclass);
21642164
expr = make_opclause(oproid, BOOLOID, false,
21652165
(Expr *) leftop, (Expr *) greaterstr);
2166-
result = lappend(result, make_restrictinfo(expr, true, true, NULL));
2166+
result = lappend(result, make_restrictinfo(expr, true, NULL));
21672167
}
21682168

21692169
return result;
@@ -2234,7 +2234,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opclass, Datum rightop)
22342234
(Expr *) leftop,
22352235
(Expr *) makeConst(datatype, -1, opr1right,
22362236
false, false));
2237-
result = list_make1(make_restrictinfo(expr, true, true, NULL));
2237+
result = list_make1(make_restrictinfo(expr, true, NULL));
22382238

22392239
/* create clause "key <= network_scan_last( rightop )" */
22402240

@@ -2249,7 +2249,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opclass, Datum rightop)
22492249
(Expr *) leftop,
22502250
(Expr *) makeConst(datatype, -1, opr2right,
22512251
false, false));
2252-
result = lappend(result, make_restrictinfo(expr, true, true, NULL));
2252+
result = lappend(result, make_restrictinfo(expr, true, NULL));
22532253

22542254
return result;
22552255
}

src/backend/optimizer/path/orindxpath.c

Lines changed: 4 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/path/orindxpath.c,v 1.72 2005/06/09 04:18:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.73 2005/07/02 23:00:40 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -90,16 +90,13 @@ create_or_index_quals(PlannerInfo *root, RelOptInfo *rel)
9090
ListCell *i;
9191

9292
/*
93-
* Find potentially interesting OR joinclauses. We must ignore any
94-
* joinclauses that are not marked valid_everywhere, because they
95-
* cannot be pushed down due to outer-join rules.
93+
* Find potentially interesting OR joinclauses.
9694
*/
9795
foreach(i, rel->joininfo)
9896
{
9997
RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
10098

101-
if (restriction_is_or_clause(rinfo) &&
102-
rinfo->valid_everywhere)
99+
if (restriction_is_or_clause(rinfo))
103100
{
104101
/*
105102
* Use the generate_bitmap_or_paths() machinery to estimate
@@ -140,8 +137,7 @@ create_or_index_quals(PlannerInfo *root, RelOptInfo *rel)
140137
* Convert the path's indexclauses structure to a RestrictInfo tree,
141138
* and add it to the rel's restriction list.
142139
*/
143-
newrinfos = make_restrictinfo_from_bitmapqual((Path *) bestpath,
144-
true, true);
140+
newrinfos = make_restrictinfo_from_bitmapqual((Path *) bestpath, true);
145141
Assert(list_length(newrinfos) == 1);
146142
or_rinfo = (RestrictInfo *) linitial(newrinfos);
147143
Assert(IsA(or_rinfo, RestrictInfo));

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