Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit64095d1

Browse files
committed
Remove PlannerInfo's join_search_private method.
Instead, use the new mechanism that allows planner extensions to storeprivate state inside a PlannerInfo, treating GEQO as an in-core plannerextension. This is a useful test of the new facility, and also buysback a few bytes of storage.To make this work, we must remove innerrel_is_unique_ext's hack oftesting whether join_search_private is set as a proxy for whetherthe join search might be retried. Add a flag that extensions canuse to explicitly signal their intentions instead.Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:http://postgr.es/m/CA+TgmoYWKHU2hKr62Toyzh-kTDEnMDeLw7gkOOnjL-TnOUq0kQ@mail.gmail.com
1 parent0132ddd commit64095d1

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-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,intnum_gene)
164164
{
165-
GeqoPrivateData*private=(GeqoPrivateData*)root->join_search_private;
165+
GeqoPrivateData*private=GetGeqoPrivateData(root);
166166
List*clumps;
167167
intrel_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 @@ intGeqo_generations;
4747
doubleGeqo_selection_bias;
4848
doubleGeqo_seed;
4949

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

5153
staticintgimme_pool_size(intnr_rel);
5254
staticintgimme_number_generations(intpool_size);
@@ -98,10 +100,16 @@ geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
98100
intmutations=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
returnbest_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,doubleseed)
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
returnpg_prng_double(&private->random_state);
3332
}
3433

3534
int
3635
geqo_randint(PlannerInfo*root,intupper,intlower)
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
@@ -706,6 +706,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, char *plan_name,
706706
root->hasAlternativeSubPlans= false;
707707
root->placeholdersFrozen= false;
708708
root->hasRecursion=hasRecursion;
709+
root->assumeReplanning= false;
709710
if (hasRecursion)
710711
root->wt_param_id=assign_special_exec_param(root);
711712
else

‎src/backend/optimizer/prep/prepjointree.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
13841384
subroot->qual_security_level=0;
13851385
subroot->placeholdersFrozen= false;
13861386
subroot->hasRecursion= false;
1387+
subroot->assumeReplanning= false;
13871388
subroot->wt_param_id=-1;
13881389
subroot->non_recursive_path=NULL;
13891390
/* 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
boolplaceholdersFrozen;
537537
/* true if planning a recursive WITH item */
538538
boolhasRecursion;
539+
/* true if a planner extension may replan this subquery */
540+
boolassumeReplanning;
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*isAltSubplanpg_node_attr(read_write_ignore);
583585
bool*isUsedSubplanpg_node_attr(read_write_ignore);
584586

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

‎src/include/optimizer/geqo.h‎

Lines changed: 11 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
externPGDLLIMPORTdoubleGeqo_selection_bias;
6465

66+
externPGDLLIMPORTintGeqo_planner_extension_id;
67+
6568
#defineDEFAULT_GEQO_SELECTION_BIAS 2.0
6669
#defineMIN_GEQO_SELECTION_BIAS 1.5
6770
#defineMAX_GEQO_SELECTION_BIAS 2.0
@@ -70,14 +73,21 @@ extern PGDLLIMPORT double Geqo_seed;/* 0 .. 1 */
7073

7174

7275
/*
73-
* Private state for a GEQO run --- accessible viaroot->join_search_private
76+
* Private state for a GEQO run --- accessible viaGetGeqoPrivateData
7477
*/
7578
typedefstruct
7679
{
7780
List*initial_rels;/* the base relations we are joining */
7881
pg_prng_staterandom_state;/* PRNG state */
7982
}GeqoPrivateData;
8083

84+
staticinlineGeqoPrivateData*
85+
GetGeqoPrivateData(PlannerInfo*root)
86+
{
87+
/* headers must be C++-compliant, so the cast is required here */
88+
return (GeqoPrivateData*)
89+
GetPlannerInfoExtensionState(root,Geqo_planner_extension_id);
90+
}
8191

8292
/* routines in geqo_main.c */
8393
externRelOptInfo*geqo(PlannerInfo*root,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp