Skip to content

Commit 9091e8d

Browse files
committed
Add the ability to extract OR indexscan conditions from OR-of-AND
join conditions in which each OR subclause includes a constraint on the same relation. This implements the other useful side-effect of conversion to CNF format, without its unpleasant side-effects. As per pghackers discussion of a few weeks ago.
1 parent bf488a6 commit 9091e8d

File tree

16 files changed

+437
-294
lines changed

16 files changed

+437
-294
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 4 additions & 3 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.272 2004/01/04 03:51:52 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.273 2004/01/05 05:07:35 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1168,8 +1168,9 @@ _copyRestrictInfo(RestrictInfo *from)
11681168
RestrictInfo *newnode = makeNode(RestrictInfo);
11691169

11701170
COPY_NODE_FIELD(clause);
1171-
COPY_SCALAR_FIELD(ispusheddown);
1172-
COPY_SCALAR_FIELD(canjoin);
1171+
COPY_SCALAR_FIELD(is_pushed_down);
1172+
COPY_SCALAR_FIELD(valid_everywhere);
1173+
COPY_SCALAR_FIELD(can_join);
11731174
COPY_BITMAPSET_FIELD(clause_relids);
11741175
COPY_BITMAPSET_FIELD(left_relids);
11751176
COPY_BITMAPSET_FIELD(right_relids);

src/backend/nodes/equalfuncs.c

Lines changed: 3 additions & 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.211 2003/12/30 23:53:14 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.212 2004/01/05 05:07:35 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -560,7 +560,8 @@ static bool
560560
_equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
561561
{
562562
COMPARE_NODE_FIELD(clause);
563-
COMPARE_SCALAR_FIELD(ispusheddown);
563+
COMPARE_SCALAR_FIELD(is_pushed_down);
564+
COMPARE_SCALAR_FIELD(valid_everywhere);
564565

565566
/*
566567
* We ignore all the remaining fields, since they may not be set yet,

src/backend/nodes/outfuncs.c

Lines changed: 5 additions & 4 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.225 2004/01/04 03:51:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.226 2004/01/05 05:07:35 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -971,7 +971,7 @@ _outIndexPath(StringInfo str, IndexPath *node)
971971
WRITE_NODE_FIELD(indexqual);
972972
WRITE_NODE_FIELD(indexjoinclauses);
973973
WRITE_ENUM_FIELD(indexscandir, ScanDirection);
974-
WRITE_FLOAT_FIELD(rows, "%.2f");
974+
WRITE_FLOAT_FIELD(rows, "%.0f");
975975
}
976976

977977
static void
@@ -1073,8 +1073,9 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
10731073

10741074
/* NB: this isn't a complete set of fields */
10751075
WRITE_NODE_FIELD(clause);
1076-
WRITE_BOOL_FIELD(ispusheddown);
1077-
WRITE_BOOL_FIELD(canjoin);
1076+
WRITE_BOOL_FIELD(is_pushed_down);
1077+
WRITE_BOOL_FIELD(valid_everywhere);
1078+
WRITE_BOOL_FIELD(can_join);
10781079
WRITE_BITMAPSET_FIELD(clause_relids);
10791080
WRITE_BITMAPSET_FIELD(left_relids);
10801081
WRITE_BITMAPSET_FIELD(right_relids);

src/backend/optimizer/path/allpaths.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.110 2003/12/17 17:07:48 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.111 2004/01/05 05:07:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -151,6 +151,17 @@ set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
151151
/* Mark rel with estimated output rows, width, etc */
152152
set_baserel_size_estimates(root, rel);
153153

154+
/* Test any partial indexes of rel for applicability */
155+
check_partial_indexes(root, rel);
156+
157+
/*
158+
* Check to see if we can extract any restriction conditions from
159+
* join quals that are OR-of-AND structures. If so, add them to the
160+
* rel's restriction list, and recompute the size estimates.
161+
*/
162+
if (create_or_index_quals(root, rel))
163+
set_baserel_size_estimates(root, rel);
164+
154165
/*
155166
* Generate paths and add them to the rel's pathlist.
156167
*
@@ -167,8 +178,6 @@ set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
167178

168179
/* Consider index paths for both simple and OR index clauses */
169180
create_index_paths(root, rel);
170-
171-
/* create_index_paths must be done before create_or_index_paths */
172181
create_or_index_paths(root, rel);
173182

174183
/* Now find the cheapest of the paths for this rel */

0 commit comments

Comments
 (0)