Skip to content

Commit 9ab4d98

Browse files
committed
Remove planner's private fields from Query struct, and put them into
a new PlannerInfo struct, which is passed around instead of the bare Query in all the planning code. This commit is essentially just a code-beautification exercise, but it does open the door to making larger changes to the planner data structures without having to muck with the widely-known Query struct.
1 parent 22dbd54 commit 9ab4d98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+852
-707
lines changed

doc/src/sgml/indexam.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.4 2005/04/20 22:19:58 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.5 2005/06/05 22:32:53 tgl Exp $
33
-->
44

55
<chapter id="indexam">
@@ -319,7 +319,7 @@ amrestrpos (IndexScanDesc scan);
319319
<para>
320320
<programlisting>
321321
void
322-
amcostestimate (Query *root,
322+
amcostestimate (PlannerInfo *root,
323323
IndexOptInfo *index,
324324
List *indexQuals,
325325
Cost *indexStartupCost,
@@ -656,7 +656,7 @@ amcostestimate (Query *root,
656656

657657
<programlisting>
658658
void
659-
amcostestimate (Query *root,
659+
amcostestimate (PlannerInfo *root,
660660
IndexOptInfo *index,
661661
List *indexQuals,
662662
Cost *indexStartupCost,
@@ -672,7 +672,7 @@ amcostestimate (Query *root,
672672
<term>root</term>
673673
<listitem>
674674
<para>
675-
The query being processed.
675+
The planner's information about the query being processed.
676676
</para>
677677
</listitem>
678678
</varlistentry>

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 13 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.304 2005/04/28 21:47:12 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.305 2005/06/05 22:32:54 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1615,18 +1615,6 @@ _copyQuery(Query *from)
16151615
COPY_NODE_FIELD(limitCount);
16161616
COPY_NODE_FIELD(setOperations);
16171617
COPY_NODE_FIELD(resultRelations);
1618-
COPY_NODE_FIELD(in_info_list);
1619-
COPY_SCALAR_FIELD(hasJoinRTEs);
1620-
COPY_SCALAR_FIELD(hasHavingQual);
1621-
1622-
/*
1623-
* We do not copy the other planner internal fields: base_rel_list,
1624-
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
1625-
* would get us into copying RelOptInfo/Path trees, which we don't
1626-
* want to do. It is necessary to copy in_info_list, hasJoinRTEs,
1627-
* and hasHavingQual for the benefit of inheritance_planner(), which
1628-
* may try to copy a Query in which these are already set.
1629-
*/
16301618

16311619
return newnode;
16321620
}

src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 5 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.241 2005/04/28 21:47:12 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.242 2005/06/05 22:32:54 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -653,10 +653,6 @@ _equalQuery(Query *a, Query *b)
653653
COMPARE_NODE_FIELD(setOperations);
654654
COMPARE_NODE_FIELD(resultRelations);
655655

656-
/*
657-
* We do not check the planner-internal fields. They might not be set
658-
* yet, and in any case they should be derivable from the other fields.
659-
*/
660656
return true;
661657
}
662658

src/backend/nodes/outfuncs.c

Lines changed: 85 additions & 3 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.252 2005/05/09 15:09:19 ishii Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.253 2005/06/05 22:32:54 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1145,6 +1145,69 @@ _outHashPath(StringInfo str, HashPath *node)
11451145
WRITE_NODE_FIELD(path_hashclauses);
11461146
}
11471147

1148+
static void
1149+
_outPlannerInfo(StringInfo str, PlannerInfo *node)
1150+
{
1151+
WRITE_NODE_TYPE("PLANNERINFO");
1152+
1153+
WRITE_NODE_FIELD(parse);
1154+
WRITE_NODE_FIELD(base_rel_list);
1155+
WRITE_NODE_FIELD(other_rel_list);
1156+
WRITE_NODE_FIELD(join_rel_list);
1157+
WRITE_NODE_FIELD(equi_key_list);
1158+
WRITE_NODE_FIELD(in_info_list);
1159+
WRITE_NODE_FIELD(query_pathkeys);
1160+
WRITE_BOOL_FIELD(hasJoinRTEs);
1161+
WRITE_BOOL_FIELD(hasHavingQual);
1162+
}
1163+
1164+
static void
1165+
_outRelOptInfo(StringInfo str, RelOptInfo *node)
1166+
{
1167+
WRITE_NODE_TYPE("RELOPTINFO");
1168+
1169+
/* NB: this isn't a complete set of fields */
1170+
WRITE_ENUM_FIELD(reloptkind, RelOptKind);
1171+
WRITE_BITMAPSET_FIELD(relids);
1172+
WRITE_FLOAT_FIELD(rows, "%.0f");
1173+
WRITE_INT_FIELD(width);
1174+
WRITE_NODE_FIELD(reltargetlist);
1175+
WRITE_NODE_FIELD(pathlist);
1176+
WRITE_NODE_FIELD(cheapest_startup_path);
1177+
WRITE_NODE_FIELD(cheapest_total_path);
1178+
WRITE_NODE_FIELD(cheapest_unique_path);
1179+
WRITE_UINT_FIELD(relid);
1180+
WRITE_ENUM_FIELD(rtekind, RTEKind);
1181+
WRITE_UINT_FIELD(min_attr);
1182+
WRITE_UINT_FIELD(max_attr);
1183+
WRITE_NODE_FIELD(indexlist);
1184+
WRITE_UINT_FIELD(pages);
1185+
WRITE_FLOAT_FIELD(tuples, "%.0f");
1186+
WRITE_NODE_FIELD(subplan);
1187+
WRITE_NODE_FIELD(baserestrictinfo);
1188+
WRITE_BITMAPSET_FIELD(outerjoinset);
1189+
WRITE_NODE_FIELD(joininfo);
1190+
WRITE_BITMAPSET_FIELD(index_outer_relids);
1191+
WRITE_NODE_FIELD(index_inner_paths);
1192+
}
1193+
1194+
static void
1195+
_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
1196+
{
1197+
WRITE_NODE_TYPE("INDEXOPTINFO");
1198+
1199+
/* NB: this isn't a complete set of fields */
1200+
WRITE_OID_FIELD(indexoid);
1201+
/* Do NOT print rel field, else infinite recursion */
1202+
WRITE_UINT_FIELD(pages);
1203+
WRITE_FLOAT_FIELD(tuples, "%.0f");
1204+
WRITE_INT_FIELD(ncolumns);
1205+
WRITE_NODE_FIELD(indexprs);
1206+
WRITE_NODE_FIELD(indpred);
1207+
WRITE_BOOL_FIELD(predOK);
1208+
WRITE_BOOL_FIELD(unique);
1209+
}
1210+
11481211
static void
11491212
_outPathKeyItem(StringInfo str, PathKeyItem *node)
11501213
{
@@ -1185,6 +1248,15 @@ _outJoinInfo(StringInfo str, JoinInfo *node)
11851248
WRITE_NODE_FIELD(jinfo_restrictinfo);
11861249
}
11871250

1251+
static void
1252+
_outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
1253+
{
1254+
WRITE_NODE_TYPE("INNERINDEXSCANINFO");
1255+
WRITE_BITMAPSET_FIELD(other_relids);
1256+
WRITE_BOOL_FIELD(isouterjoin);
1257+
WRITE_NODE_FIELD(best_innerpath);
1258+
}
1259+
11881260
static void
11891261
_outInClauseInfo(StringInfo str, InClauseInfo *node)
11901262
{
@@ -1395,8 +1467,6 @@ _outQuery(StringInfo str, Query *node)
13951467
WRITE_NODE_FIELD(limitCount);
13961468
WRITE_NODE_FIELD(setOperations);
13971469
WRITE_NODE_FIELD(resultRelations);
1398-
1399-
/* planner-internal fields are not written out */
14001470
}
14011471

14021472
static void
@@ -1905,6 +1975,15 @@ _outNode(StringInfo str, void *obj)
19051975
case T_HashPath:
19061976
_outHashPath(str, obj);
19071977
break;
1978+
case T_PlannerInfo:
1979+
_outPlannerInfo(str, obj);
1980+
break;
1981+
case T_RelOptInfo:
1982+
_outRelOptInfo(str, obj);
1983+
break;
1984+
case T_IndexOptInfo:
1985+
_outIndexOptInfo(str, obj);
1986+
break;
19081987
case T_PathKeyItem:
19091988
_outPathKeyItem(str, obj);
19101989
break;
@@ -1914,6 +1993,9 @@ _outNode(StringInfo str, void *obj)
19141993
case T_JoinInfo:
19151994
_outJoinInfo(str, obj);
19161995
break;
1996+
case T_InnerIndexscanInfo:
1997+
_outInnerIndexscanInfo(str, obj);
1998+
break;
19171999
case T_InClauseInfo:
19182000
_outInClauseInfo(str, obj);
19192001
break;

src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.177 2005/04/28 21:47:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.178 2005/06/05 22:32:54 tgl Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -156,8 +156,6 @@ _readQuery(void)
156156
READ_NODE_FIELD(setOperations);
157157
READ_NODE_FIELD(resultRelations);
158158

159-
/* planner-internal fields are left zero */
160-
161159
READ_DONE();
162160
}
163161

src/backend/optimizer/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ planner()
245245
Optimizer Data Structures
246246
-------------------------
247247

248+
PlannerInfo - global information for planning a particular Query
249+
248250
RelOptInfo - a relation or joined relations
249251

250252
RestrictInfo - WHERE clauses, like "x = 3" or "y = z"

src/backend/optimizer/geqo/geqo_eval.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.73 2004/12/31 21:59:58 pgsql Exp $
9+
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.74 2005/06/05 22:32:55 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -31,7 +31,7 @@
3131
#include "utils/memutils.h"
3232

3333

34-
static bool desirable_join(Query *root,
34+
static bool desirable_join(PlannerInfo *root,
3535
RelOptInfo *outer_rel, RelOptInfo *inner_rel);
3636

3737

@@ -241,7 +241,7 @@ gimme_tree(Gene *tour, int num_gene, GeqoEvalData *evaldata)
241241
* Heuristics for gimme_tree: do we want to join these two relations?
242242
*/
243243
static bool
244-
desirable_join(Query *root,
244+
desirable_join(PlannerInfo *root,
245245
RelOptInfo *outer_rel, RelOptInfo *inner_rel)
246246
{
247247
ListCell *l;

src/backend/optimizer/geqo/geqo_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.48 2004/12/31 21:59:58 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.49 2005/06/05 22:32:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -63,7 +63,7 @@ static int gimme_number_generations(int pool_size);
6363
*/
6464

6565
RelOptInfo *
66-
geqo(Query *root, int number_of_rels, List *initial_rels)
66+
geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
6767
{
6868
GeqoEvalData evaldata;
6969
int generation;

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