Skip to content

Commit 14d6781

Browse files
robertmhaasCommitfest Bot
authored andcommitted
Remove PlannerInfo's join_search_private method.
Instead, use the new mechanism that allows planner extensions to store private state inside a PlannerInfo, treating GEQO as an in-core planner extension. This is a useful test of the new facility, and also buys back a few bytes of storage. To make this work, we must remove innerrel_is_unique_ext's hack of testing whether join_search_private is set as a proxy for whether the join search might be retried. Add a flag that extensions can use to explicitly signal their intentions instead.
1 parent f6a2e60 commit 14d6781

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

src/backend/optimizer/geqo/geqo_eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ geqo_eval(PlannerInfo *root, Gene *tour, int num_gene)
162162
RelOptInfo *
163163
gimme_tree(PlannerInfo *root, Gene *tour, int num_gene)
164164
{
165-
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
165+
GeqoPrivateData *private = GetGeqoPrivateData(root);
166166
List *clumps;
167167
int rel_count;
168168

src/backend/optimizer/geqo/geqo_main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ int Geqo_generations;
4747
double Geqo_selection_bias;
4848
double Geqo_seed;
4949

50+
/* GEQO is treated as an in-core planner extension */
51+
int Geqo_planner_extension_id = -1;
5052

5153
static int gimme_pool_size(int nr_rel);
5254
static int gimme_number_generations(int pool_size);
@@ -98,10 +100,16 @@ geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
98100
int mutations = 0;
99101
#endif
100102

103+
if (Geqo_planner_extension_id < 0)
104+
Geqo_planner_extension_id = GetPlannerExtensionId("geqo");
105+
101106
/* set up private information */
102-
root->join_search_private = &private;
107+
SetPlannerInfoExtensionState(root, Geqo_planner_extension_id, &private);
103108
private.initial_rels = initial_rels;
104109

110+
/* inform core planner that we may replan */
111+
root->assumeReplanning = true;
112+
105113
/* initialize private number generator */
106114
geqo_set_seed(root, Geqo_seed);
107115

@@ -304,7 +312,7 @@ geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
304312
free_pool(root, pool);
305313

306314
/* ... clear root pointer to our private storage */
307-
root->join_search_private = NULL;
315+
SetPlannerInfoExtensionState(root, Geqo_planner_extension_id, NULL);
308316

309317
return best_rel;
310318
}

src/backend/optimizer/geqo/geqo_random.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@
1515

1616
#include "optimizer/geqo_random.h"
1717

18-
1918
void
2019
geqo_set_seed(PlannerInfo *root, double seed)
2120
{
22-
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
21+
GeqoPrivateData *private = GetGeqoPrivateData(root);
2322

2423
pg_prng_fseed(&private->random_state, seed);
2524
}
2625

2726
double
2827
geqo_rand(PlannerInfo *root)
2928
{
30-
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
29+
GeqoPrivateData *private = GetGeqoPrivateData(root);
3130

3231
return pg_prng_double(&private->random_state);
3332
}
3433

3534
int
3635
geqo_randint(PlannerInfo *root, int upper, int lower)
3736
{
38-
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
37+
GeqoPrivateData *private = GetGeqoPrivateData(root);
3938

4039
/*
4140
* In current usage, "lower" is never negative so we can just use

src/backend/optimizer/plan/analyzejoins.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,17 +1425,14 @@ innerrel_is_unique_ext(PlannerInfo *root,
14251425
*
14261426
* However, in normal planning mode, caching this knowledge is totally
14271427
* pointless; it won't be queried again, because we build up joinrels
1428-
* from smaller to larger. It is useful in GEQO mode, where the
1429-
* knowledge can be carried across successive planning attempts; and
1430-
* it's likely to be useful when using join-search plugins, too. Hence
1431-
* cache when join_search_private is non-NULL. (Yeah, that's a hack,
1432-
* but it seems reasonable.)
1428+
* from smaller to larger. It's only useful when using GEQO or
1429+
* another planner extension that attempts planning multiple times.
14331430
*
14341431
* Also, allow callers to override that heuristic and force caching;
14351432
* that's useful for reduce_unique_semijoins, which calls here before
14361433
* the normal join search starts.
14371434
*/
1438-
if (force_cache || root->join_search_private)
1435+
if (force_cache || root->assumeReplanning)
14391436
{
14401437
old_context = MemoryContextSwitchTo(root->planner_cxt);
14411438
innerrel->non_unique_for_rels =

src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
703703
root->hasAlternativeSubPlans = false;
704704
root->placeholdersFrozen = false;
705705
root->hasRecursion = hasRecursion;
706+
root->assumeReplanning = false;
706707
if (hasRecursion)
707708
root->wt_param_id = assign_special_exec_param(root);
708709
else

src/backend/optimizer/prep/prepjointree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
13831383
subroot->qual_security_level = 0;
13841384
subroot->placeholdersFrozen = false;
13851385
subroot->hasRecursion = false;
1386+
subroot->assumeReplanning = false;
13861387
subroot->wt_param_id = -1;
13871388
subroot->non_recursive_path = NULL;
13881389
/* We don't currently need a top JoinDomain for the subroot */

src/include/nodes/pathnodes.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ struct PlannerInfo
536536
bool placeholdersFrozen;
537537
/* true if planning a recursive WITH item */
538538
bool hasRecursion;
539+
/* true if a planner extension may replan this subquery */
540+
bool assumeReplanning;
539541

540542
/*
541543
* The rangetable index for the RTE_GROUP RTE, or 0 if there is no
@@ -582,9 +584,6 @@ struct PlannerInfo
582584
bool *isAltSubplan pg_node_attr(read_write_ignore);
583585
bool *isUsedSubplan pg_node_attr(read_write_ignore);
584586

585-
/* optional private data for join_search_hook, e.g., GEQO */
586-
void *join_search_private pg_node_attr(read_write_ignore);
587-
588587
/* Does this query modify any partition key columns? */
589588
bool partColsUpdated;
590589

src/include/optimizer/geqo.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "common/pg_prng.h"
2626
#include "nodes/pathnodes.h"
27+
#include "optimizer/extendplan.h"
2728
#include "optimizer/geqo_gene.h"
2829

2930

@@ -62,6 +63,8 @@ extern PGDLLIMPORT int Geqo_generations; /* 1 .. inf, or 0 to use default */
6263

6364
extern PGDLLIMPORT double Geqo_selection_bias;
6465

66+
extern PGDLLIMPORT int Geqo_planner_extension_id;
67+
6568
#define DEFAULT_GEQO_SELECTION_BIAS 2.0
6669
#define MIN_GEQO_SELECTION_BIAS 1.5
6770
#define MAX_GEQO_SELECTION_BIAS 2.0
@@ -70,14 +73,19 @@ extern PGDLLIMPORT double Geqo_seed; /* 0 .. 1 */
7073

7174

7275
/*
73-
* Private state for a GEQO run --- accessible via root->join_search_private
76+
* Private state for a GEQO run --- accessible via GetGeqoPrivateData
7477
*/
7578
typedef struct
7679
{
7780
List *initial_rels; /* the base relations we are joining */
7881
pg_prng_state random_state; /* PRNG state */
7982
} GeqoPrivateData;
8083

84+
static inline GeqoPrivateData *
85+
GetGeqoPrivateData(PlannerInfo *root)
86+
{
87+
return GetPlannerInfoExtensionState(root, Geqo_planner_extension_id);
88+
}
8189

8290
/* routines in geqo_main.c */
8391
extern RelOptInfo *geqo(PlannerInfo *root,

0 commit comments

Comments
 (0)