Skip to content

Commit 0e89516

Browse files
committed
Arrange AQO core patch and code according to a fresh PostgreSQL changes.
1 parent 5ba53ad commit 0e89516

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
lines changed

aqo.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ _PG_init(void)
205205
NULL
206206
);
207207

208+
prev_shmem_request_hook = shmem_request_hook;
209+
prev_shmem_request_hook = aqo_shmem_request;
208210
prev_shmem_startup_hook = shmem_startup_hook;
209211
shmem_startup_hook = aqo_init_shmem;
210212
prev_planner_hook = planner_hook;
@@ -250,7 +252,6 @@ _PG_init(void)
250252
RegisterAQOPlanNodeMethods();
251253

252254
MarkGUCPrefixReserved("aqo");
253-
RequestAddinShmemSpace(aqo_memsize());
254255
}
255256

256257
PG_FUNCTION_INFO_V1(invalidate_deactivated_queries_cache);

aqo_master.patch

+40-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
diff --git a/contrib/Makefile b/contrib/Makefile
2+
index bbf220407b..8225105893 100644
3+
--- a/contrib/Makefile
4+
+++ b/contrib/Makefile
5+
@@ -6,6 +6,7 @@ include $(top_builddir)/src/Makefile.global
6+
7+
SUBDIRS = \
8+
adminpack \
9+
+ aqo \
10+
amcheck \
11+
auth_delay \
12+
auto_explain \
113
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
2-
index d2a2479822..3109d8751e 100644
14+
index 5d1f7089da..268b50071d 100644
315
--- a/src/backend/commands/explain.c
416
+++ b/src/backend/commands/explain.c
517
@@ -24,6 +24,7 @@
@@ -45,7 +57,7 @@ index d2a2479822..3109d8751e 100644
4557
if (es->format == EXPLAIN_FORMAT_TEXT)
4658
appendStringInfoChar(es->str, '\n');
4759
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
48-
index 836f427ea8..2b6184f349 100644
60+
index 51d630fa89..c46aca258b 100644
4961
--- a/src/backend/nodes/copyfuncs.c
5062
+++ b/src/backend/nodes/copyfuncs.c
5163
@@ -136,6 +136,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
@@ -57,7 +69,7 @@ index 836f427ea8..2b6184f349 100644
5769

5870
/*
5971
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
60-
index b1f2de8b28..9cc22c3c10 100644
72+
index ce12915592..30e7f35a6c 100644
6173
--- a/src/backend/nodes/outfuncs.c
6274
+++ b/src/backend/nodes/outfuncs.c
6375
@@ -356,6 +356,7 @@ _outPlanInfo(StringInfo str, const Plan *node)
@@ -69,10 +81,10 @@ index b1f2de8b28..9cc22c3c10 100644
6981

7082
/*
7183
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
72-
index ddf76ac778..c28acb46d8 100644
84+
index 6a05b69415..f61432a6e7 100644
7385
--- a/src/backend/nodes/readfuncs.c
7486
+++ b/src/backend/nodes/readfuncs.c
75-
@@ -1855,6 +1855,11 @@ ReadCommonPlan(Plan *local_node)
87+
@@ -1857,6 +1857,11 @@ ReadCommonPlan(Plan *local_node)
7688
READ_NODE_FIELD(initPlan);
7789
READ_BITMAPSET_FIELD(extParam);
7890
READ_BITMAPSET_FIELD(allParam);
@@ -85,10 +97,10 @@ index ddf76ac778..c28acb46d8 100644
8597

8698
/*
8799
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
88-
index b787c6f81a..18deca6d72 100644
100+
index fcc26b01a4..b3f1535c4b 100644
89101
--- a/src/backend/optimizer/path/costsize.c
90102
+++ b/src/backend/optimizer/path/costsize.c
91-
@@ -98,6 +98,11 @@
103+
@@ -99,6 +99,11 @@
92104
#include "utils/spccache.h"
93105
#include "utils/tuplesort.h"
94106

@@ -100,15 +112,15 @@ index b787c6f81a..18deca6d72 100644
100112

101113
#define LOG2(x) (log(x) / 0.693147180559945)
102114

103-
@@ -189,7 +194,6 @@ static Cost append_nonpartial_cost(List *subpaths, int numpaths,
115+
@@ -190,7 +195,6 @@ static Cost append_nonpartial_cost(List *subpaths, int numpaths,
104116
static void set_rel_width(PlannerInfo *root, RelOptInfo *rel);
105117
static double relation_byte_size(double tuples, int width);
106118
static double page_size(double tuples, int width);
107119
-static double get_parallel_divisor(Path *path);
108120

109121

110122
/*
111-
@@ -5226,6 +5230,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
123+
@@ -5272,6 +5276,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
112124
}
113125

114126

@@ -167,7 +179,7 @@ index b787c6f81a..18deca6d72 100644
167179
/*
168180
* set_baserel_size_estimates
169181
* Set the size estimates for the given base relation.
170-
@@ -5242,19 +5298,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
182+
@@ -5288,19 +5344,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals)
171183
void
172184
set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
173185
{
@@ -188,7 +200,7 @@ index b787c6f81a..18deca6d72 100644
188200

189201
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);
190202

191-
@@ -5265,13 +5312,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
203+
@@ -5311,13 +5358,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
192204
* get_parameterized_baserel_size
193205
* Make a size estimate for a parameterized scan of a base relation.
194206
*
@@ -224,7 +236,7 @@ index b787c6f81a..18deca6d72 100644
224236
{
225237
List *allclauses;
226238
double nrows;
227-
@@ -5300,6 +5367,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
239+
@@ -5346,6 +5413,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
228240
* set_joinrel_size_estimates
229241
* Set the size estimates for the given join relation.
230242
*
@@ -261,7 +273,7 @@ index b787c6f81a..18deca6d72 100644
261273
* The rel's targetlist must have been constructed already, and a
262274
* restriction clause list that matches the given component rels must
263275
* be provided.
264-
@@ -5319,11 +5416,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
276+
@@ -5365,11 +5462,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel,
265277
* build_joinrel_tlist, and baserestrictcost is not used for join rels.
266278
*/
267279
void
@@ -278,7 +290,7 @@ index b787c6f81a..18deca6d72 100644
278290
{
279291
rel->rows = calc_joinrel_size_estimate(root,
280292
rel,
281-
@@ -5339,6 +5436,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
293+
@@ -5385,6 +5482,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
282294
* get_parameterized_joinrel_size
283295
* Make a size estimate for a parameterized scan of a join relation.
284296
*
@@ -314,7 +326,7 @@ index b787c6f81a..18deca6d72 100644
314326
* 'rel' is the joinrel under consideration.
315327
* 'outer_path', 'inner_path' are (probably also parameterized) Paths that
316328
* produce the relations being joined.
317-
@@ -5351,11 +5477,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
329+
@@ -5397,11 +5523,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
318330
* set_joinrel_size_estimates must have been applied already.
319331
*/
320332
double
@@ -331,7 +343,7 @@ index b787c6f81a..18deca6d72 100644
331343
{
332344
double nrows;
333345

334-
@@ -6072,7 +6198,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
346+
@@ -6118,7 +6244,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
335347
/* Should only be applied to base relations */
336348
Assert(rel->relid > 0);
337349

@@ -340,7 +352,7 @@ index b787c6f81a..18deca6d72 100644
340352

341353
cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root);
342354

343-
@@ -6359,7 +6485,7 @@ page_size(double tuples, int width)
355+
@@ -6405,7 +6531,7 @@ page_size(double tuples, int width)
344356
* Estimate the fraction of the work that each worker will do given the
345357
* number of workers budgeted for the path.
346358
*/
@@ -350,18 +362,18 @@ index b787c6f81a..18deca6d72 100644
350362
{
351363
double parallel_divisor = path->parallel_workers;
352364
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
353-
index db11936efe..8b5cd8426e 100644
365+
index 76606faa3e..3981bea57a 100644
354366
--- a/src/backend/optimizer/plan/createplan.c
355367
+++ b/src/backend/optimizer/plan/createplan.c
356-
@@ -71,6 +71,7 @@
368+
@@ -70,6 +70,7 @@
357369
#define CP_LABEL_TLIST 0x0004 /* tlist must contain sortgrouprefs */
358370
#define CP_IGNORE_TLIST 0x0008 /* caller will replace tlist */
359371

360372
+create_plan_hook_type create_plan_hook = NULL;
361373

362374
static Plan *create_plan_recurse(PlannerInfo *root, Path *best_path,
363375
int flags);
364-
@@ -547,6 +548,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
376+
@@ -546,6 +547,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
365377
break;
366378
}
367379

@@ -372,7 +384,7 @@ index db11936efe..8b5cd8426e 100644
372384
return plan;
373385
}
374386

375-
@@ -5373,6 +5378,7 @@ copy_generic_path_info(Plan *dest, Path *src)
387+
@@ -5372,6 +5377,7 @@ copy_generic_path_info(Plan *dest, Path *src)
376388
dest->plan_width = src->pathtarget->width;
377389
dest->parallel_aware = src->parallel_aware;
378390
dest->parallel_safe = src->parallel_safe;
@@ -381,7 +393,7 @@ index db11936efe..8b5cd8426e 100644
381393

382394
/*
383395
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
384-
index 9a4accb4d9..8554e6723e 100644
396+
index a0f2390334..51f5a7d626 100644
385397
--- a/src/backend/optimizer/plan/planner.c
386398
+++ b/src/backend/optimizer/plan/planner.c
387399
@@ -143,7 +143,8 @@ static List *extract_rollup_sets(List *groupingSets);
@@ -443,7 +455,7 @@ index 9a4accb4d9..8554e6723e 100644
443455
gd,
444456
extra->targetList);
445457

446-
@@ -6701,13 +6704,15 @@ create_partial_grouping_paths(PlannerInfo *root,
458+
@@ -6708,13 +6711,15 @@ create_partial_grouping_paths(PlannerInfo *root,
447459
if (cheapest_total_path != NULL)
448460
dNumPartialGroups =
449461
get_number_of_groups(root,
@@ -528,7 +540,7 @@ index 520409f4ba..fd0524d72b 100644
528540

529541
return ppi;
530542
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
531-
index 71cbc1c3d8..f78d004d1d 100644
543+
index fa1f589fad..f758776ac5 100644
532544
--- a/src/backend/utils/adt/selfuncs.c
533545
+++ b/src/backend/utils/adt/selfuncs.c
534546
@@ -143,6 +143,7 @@
@@ -584,7 +596,7 @@ index 666977fb1f..33b109afbb 100644
584596
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
585597
ParamListInfo params, DestReceiver *dest);
586598
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
587-
index 244d1e1197..315b9fe776 100644
599+
index a6e5db4eec..5b7bf8b8b7 100644
588600
--- a/src/include/nodes/pathnodes.h
589601
+++ b/src/include/nodes/pathnodes.h
590602
@@ -757,6 +757,10 @@ typedef struct RelOptInfo
@@ -615,7 +627,7 @@ index 244d1e1197..315b9fe776 100644
615627
* Is given relation partitioned?
616628
@@ -1153,6 +1163,10 @@ typedef struct ParamPathInfo
617629
Relids ppi_req_outer; /* rels supplying parameters used by path */
618-
Cardinality ppi_rows; /* estimated number of result tuples */
630+
Cardinality ppi_rows; /* estimated number of result tuples */
619631
List *ppi_clauses; /* join clauses available from outer rels */
620632
+
621633
+ /* AQO DEBUG purposes */
@@ -625,7 +637,7 @@ index 244d1e1197..315b9fe776 100644
625637

626638

627639
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
628-
index e43e360d9b..c4234e2e5b 100644
640+
index 0ea9a22dfb..64db54ff30 100644
629641
--- a/src/include/nodes/plannodes.h
630642
+++ b/src/include/nodes/plannodes.h
631643
@@ -159,6 +159,12 @@ typedef struct Plan
@@ -758,7 +770,7 @@ index c4f61c1a09..ade32a6f44 100644
758770
* prototypes for plan/planmain.c
759771
*/
760772
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
761-
index c313a08d54..e3d0d493d8 100644
773+
index d485b9bfcd..175660ecb9 100644
762774
--- a/src/include/utils/selfuncs.h
763775
+++ b/src/include/utils/selfuncs.h
764776
@@ -144,6 +144,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,

aqo_shared.c

+11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ typedef struct
1919
#define free_space(hdr) (uint32) (temp_storage_size - sizeof(dsm_seg_hdr) - hdr->delta)
2020
#define addr(delta) ((char *) dsm_segment_address(seg) + sizeof(dsm_seg_hdr) + delta)
2121

22+
shmem_request_hook_type prev_shmem_request_hook = NULL;
2223
shmem_startup_hook_type prev_shmem_startup_hook = NULL;
24+
2325
AQOSharedState *aqo_state = NULL;
2426
HTAB *fss_htab = NULL;
2527
static int aqo_htab_max_items = 1000;
@@ -163,6 +165,15 @@ aqo_detach_shmem(int code, Datum arg)
163165
seg = NULL;
164166
}
165167

168+
void
169+
aqo_shmem_request(void)
170+
{
171+
if (prev_shmem_request_hook)
172+
prev_shmem_request_hook();
173+
174+
RequestAddinShmemSpace(aqo_memsize());
175+
}
176+
166177
void
167178
aqo_init_shmem(void)
168179
{

aqo_shared.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define AQO_SHARED_H
33

44

5+
#include "miscadmin.h"
56
#include "storage/dsm.h"
67
#include "storage/ipc.h"
78
#include "storage/lwlock.h"
@@ -28,6 +29,7 @@ typedef struct AQOSharedState
2829
} AQOSharedState;
2930

3031

32+
extern shmem_request_hook_type prev_shmem_request_hook;
3133
extern shmem_startup_hook_type prev_shmem_startup_hook;
3234
extern AQOSharedState *aqo_state;
3335
extern HTAB *fss_htab;
@@ -38,6 +40,7 @@ extern void reset_dsm_cache(void);
3840
extern void *get_dsm_all(uint32 *size);
3941
extern char *get_cache_address(void);
4042
extern uint32 get_dsm_cache_pos(uint32 size);
43+
extern void aqo_shmem_request(void);
4144
extern void aqo_init_shmem(void);
4245

4346
#endif /* AQO_SHARED_H */

0 commit comments

Comments
 (0)