10000 Add a hook to CreateExtension() · postgrespro/aqo@730ec04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 730ec04

Browse files
author
Alexandra Pervushina
committed
Add a hook to CreateExtension()
1 parent 0ccbb7e commit 730ec04

File tree

2 files changed

+76
-23
lines changed

2 files changed

+76
-23
lines changed

aqo.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ MemoryContext AQOStorageMemCtx = NULL;
9898
/* Additional plan info */
9999
int njoins;
100100

101+
CreateExtension_hook_type CreateExtension_next = NULL;
102+
101103
/*****************************************************************************
102104
*
103105
* CREATE/DROP EXTENSION FUNCTIONS
@@ -120,6 +122,17 @@ aqo_free_callback(ResourceReleasePhase phase,
120122
}
121123
}
122124

125+
static void
126+
create_aqo_hook(char *extname)
127+
{
128+
if (CreateExtension_next)
129+
CreateExtension_next(char *extname);
130+
131+
if (strcmp(extname, "aqo") == 0)
132+
elog(NOTICE, "aqo create hook working!");
133+
134+
}
135+
123136
void
124137
_PG_init(void)
125138
{
@@ -360,6 +373,9 @@ _PG_init(void)
360373
RegisterResourceReleaseCallback(aqo_free_callback, NULL);
361374
RegisterAQOPlanNodeMethods();
362375

376+
CreateExtension_next = CreateExtension_hook;
377+
CreateExtension_hook = create_aqo_hook;
378+
363379
MarkGUCPrefixReserved("aqo");
364380
}
365381

aqo_pg15.patch

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/contrib/Makefile b/contrib/Makefile
2-
index bbf220407b..8c3dc186ef 100644
2+
index bbf220407b0..8c3dc186efa 100644
33
--- a/contrib/Makefile
44
+++ b/contrib/Makefile
5 10000 5
@@ -7,6 +7,7 @@ include $(top_builddir)/src/Makefile.global
@@ -11,7 +11,7 @@ index bbf220407b..8c3dc186ef 100644
1111
auto_explain \
1212
basic_archive \
1313
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
14-
index 060c6186dd..742a0a3e84 100644
14+
index 060c6186ddd..742a0a3e844 100644
1515
--- a/src/backend/commands/explain.c
1616
+++ b/src/backend/commands/explain.c
1717
@@ -24,6 +24,7 @@
@@ -56,8 +56,31 @@ index 060c6186dd..742a0a3e84 100644
5656
/* in text format, first line ends here */
5757
if (es->format == EXPLAIN_FORMAT_TEXT)
5858
appendStringInfoChar(es->str, '\n');
59+
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
60+
index 3f750d34b36..29fbf1796e7 100644
61+
--- a/src/backend/commands/extension.c
62+
+++ b/src/backend/commands/extension.c
63+
@@ -66,6 +66,8 @@
64+
#include "utils/snapmgr.h"
65+
#include "utils/varlena.h"
66+
67+
+/* Hook for plugins to get control in CreateExtension() */
68+
+CreateExtension_hook_type CreateExtension_hook = NULL;
69+
70+
/* Globally visible state variables */
71+
bool creating_extension = false;
72+
@@ -1768,6 +1770,9 @@ CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
73+
elog(ERROR, "unrecognized option: %s", defel->defname);
74+
}
75+
76+
+ if (CreateExtension_hook)
77+
+ CreateExtension_hook(stmt->extname);
78+
+
79+
/* Call CreateExtensionInternal to do the real work. */
80+
return CreateExtensionInternal(stmt->extname,
81+
schemaName,
5982
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
60-
index b39b77050e..f6262419e9 100644
83+
index b39b77050e0..f6262419e92 100644
6184
--- a/src/backend/nodes/copyfuncs.c
6285
+++ b/src/backend/nodes/copyfuncs.c
6386
@@ -136,6 +136,7 @@ CopyPlanFields(const Plan *from, Plan *newnode)
@@ -69,7 +92,7 @@ index b39b77050e..f6262419e9 100644
6992

7093
/*
7194
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
72-
index 3f8e58626c..256c76acf2 100644
95+
index 3f8e58626cc..256c76acf29 100644
7396
--- a/src/backend/nodes/outfuncs.c
7497
+++ b/src/backend/nodes/outfuncs.c
7598
@@ -356,6 +356,7 @@ _outPlanInfo(StringInfo str, const Plan *node)
@@ -81,7 +104,7 @@ index 3f8e58626c..256c76acf2 100644
81104

82105
/*
83106
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
84-
index c84e5af3a2..ae0e78b142 100644
107+
index c84e5af3a26..ae0e78b1424 100644
85108
--- a/src/backend/nodes/readfuncs.c
86109
+++ b/src/backend/nodes/readfuncs.c
87110
@@ -1666,6 +1666,11 @@ ReadCommonPlan(Plan *local_node)
@@ -97,7 +120,7 @@ index c84e5af3a2..ae0e78b142 100644
97120

98121
/*
99122
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
100-
index 0ba26b207b..7baf41539e 100644
123+
index 0ba26b207b0..7baf41539e1 100644
101124
--- a/src/backend/optimizer/path/costsize.c
102125
+++ b/src/backend/optimizer/path/costsize.c
103126
@@ -99,6 +99,11 @@
@@ -362,7 +385,7 @@ index 0ba26b207b..7baf41539e 100644
362385
{
363386
double parallel_divisor = path->parallel_workers;
364387
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
365-
index 1bc59c9457..81cf03514d 100644
388+
index 1bc59c94578..81cf03514d3 100644
366389
--- a/src/backend/optimizer/plan/createplan.c
367390
+++ b/src/backend/optimizer/plan/createplan.c
368391
@@ -70,6 +70,7 @@
@@ -393,7 +416,7 @@ index 1bc59c9457..81cf03514d 100644
393416

394417
/*
395418
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
396-
index 468105d91e..63822050ff 100644
419+
index c588693dc43..1ad88d77ce5 100644
397420
--- a/src/backend/optimizer/plan/planner.c
398421
+++ b/src/backend/optimizer/plan/planner.c
399422
@@ -143,7 +143,8 @@ static List *extract_rollup_sets(List *groupingSets);
@@ -406,7 +429,7 @@ index 468105d91e..63822050ff 100644
406429
grouping_sets_data *gd,
407430
List *target_list);
408431
static RelOptInfo *create_grouping_paths(PlannerInfo *root,
409-
@@ -3220,7 +3221,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
432+
@@ -3221,7 +3222,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
410433
*/
411434
static double
412435
get_number_of_groups(PlannerInfo *root,
@@ -416,7 +439,7 @@ index 468105d91e..63822050ff 100644
416439
grouping_sets_data *gd,
417440
List *target_list)
418441
{
419-
@@ -3257,7 +3259,7 @@ get_number_of_groups(PlannerInfo *root,
442+
@@ -3258,7 +3260,7 @@ get_number_of_groups(PlannerInfo *root,
420443
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
421444
double numGroups = estimate_num_groups(root,
422445
groupExprs,
@@ -425,7 +448,7 @@ index 468105d91e..63822050ff 100644
425448
&gset,
426449
NULL);
427450

428-
@@ -3283,7 +3285,7 @@ get_number_of_groups(PlannerInfo *root,
451+
@@ -3284,7 +3286,7 @@ get_number_of_groups(PlannerInfo *root,
429452
GroupingSetData *gs = lfirst_node(GroupingSetData, lc2);
430453
double numGroups = estimate_num_groups(root,
431454
groupExprs,
@@ -434,7 +457,7 @@ index 468105d91e..63822050ff 100644
434457
&gset,
435458
NULL);
436459

437-
@@ -3300,8 +3302,8 @@ get_number_of_groups(PlannerInfo *root,
460+
@@ -3301,8 +3303,8 @@ get_number_of_groups(PlannerInfo *root,
438461
groupExprs = get_sortgrouplist_exprs(parse->groupClause,
439462
target_list);
440463

@@ -445,7 +468,7 @@ index 468105d91e..63822050ff 100644
445468
}
446469
}
447470
else if (parse->groupingSets)
448-
@@ -3688,7 +3690,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
471+
@@ -3689,7 +3691,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel,
449472
* Estimate number of groups.
450473
*/
451474
dNumGroups = get_number_of_groups(root,
@@ -455,7 +478,7 @@ index 468105d91e..63822050ff 100644
455478
gd,
456479
extra->targetList);
457480

458-
@@ -6653,13 +6656,15 @@ create_partial_grouping_paths(PlannerInfo *root,
481+
@@ -6654,13 +6657,15 @@ create_partial_grouping_paths(PlannerInfo *root,
459482
if (cheapest_total_path != NULL)
460483
dNumPartialGroups =
461484
get_number_of_groups(root,
@@ -474,7 +497,7 @@ index 468105d91e..63822050ff 100644
474497
extra->targetList);
475498

476499
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
477-
index 520409f4ba..fd0524d72b 100644
500+
index 3c75fd56f22..f15d22c41be 100644
478501
--- a/src/backend/optimizer/util/relnode.c
479502
+++ b/src/backend/optimizer/util/relnode.c
480503
@@ -259,6 +259,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
@@ -540,7 +563,7 @@ index 520409f4ba..fd0524d72b 100644
540563

541564
return ppi;
542565
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
543-
index 8d1b374bdf..ac4ea7b6e4 100644
566+
index 2dd399d5e37..53178369c70 100644
544567
--- a/src/backend/utils/adt/selfuncs.c
545568
+++ b/src/backend/utils/adt/selfuncs.c
546569
@@ -143,6 +143,7 @@
@@ -573,7 +596,7 @@ index 8d1b374bdf..ac4ea7b6e4 100644
573596
* estimate_num_groups - Estimate number of groups in a grouped query
574597
*
575598
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
576-
index 666977fb1f..33b109afbb 100644
599+
index 666977fb1f8..33b109afbbd 100644
577600
--- a/src/include/commands/explain.h
578601
+++ b/src/include/commands/explain.h
579602
@@ -75,6 +75,18 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
@@ -595,8 +618,22 @@ index 666977fb1f..33b109afbb 100644
595618

596619
extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
597620
ParamListInfo params, DestReceiver *dest);
621+
diff --git a/src/include/commands/extension.h b/src/include/commands/extension.h
622+
index e24e3759f0c..2f98d8cb323 100644
623+
--- a/src/include/commands/extension.h
624+
+++ b/src/include/commands/extension.h
625+
@@ -30,6 +30,9 @@
626+
extern PGDLLIMPORT bool creating_extension;
627+
extern PGDLLIMPORT Oid CurrentExtensionObject;
628+
629+
+typedef void (*CreateExtension_hook_type) (char *extname);
630+
+extern PGDLLIMPORT CreateExtension_hook_type CreateExtension_hook;
631+
+
632+
633+
extern ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt);
634+
598635
diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
599-
index 8556b2ffe7..48b191e426 100644
636+
index cbaefd9f043..06d8bac7d16 100644
600637
--- a/src/include/nodes/pathnodes.h
601638
+++ b/src/include/nodes/pathnodes.h
602639
@@ -757,6 +757,10 @@ typedef struct RelOptInfo
@@ -637,7 +674,7 @@ index 8556b2ffe7..48b191e426 100644
637674

638675

639676
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
640-
index 0ea9a22dfb..d084e4f8a0 100644
677+
index 493a2a9e4a5..adb7f4134c4 100644
641678
--- a/src/include/nodes/plannodes.h
642679
+++ b/src/include/nodes/plannodes.h
643680
@@ -159,6 +159,9 @@ typedef struct Plan
@@ -651,7 +688,7 @@ index 0ea9a22dfb..d084e4f8a0 100644
651688

652689
/* ----------------
653690
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
654-
index bc12071af6..13fa62652f 100644
691+
index bc12071af6e..13fa62652fa 100644
655692
--- a/src/include/optimizer/cost.h
656693
+++ b/src/include/optimizer/cost.h
657694
@@ -41,6 +41,37 @@ typedef enum
@@ -735,7 +772,7 @@ index bc12071af6..13fa62652f 100644
735772

736773
#endif /* COST_H */
737774
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
738-
index d2d46b15df..88608af01d 100644
775+
index d2d46b15df5..88608af01d7 100644
739776
--- a/src/include/optimizer/pathnode.h
740777
+++ b/src/include/optimizer/pathnode.h
741778
@@ -18,6 +18,10 @@
@@ -750,7 +787,7 @@ index d2d46b15df..88608af01d 100644
750787
* prototypes for pathnode.c
751788
*/
752789
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h
753-
index c4f61c1a09..ade32a6f44 100644
790+
index c4f61c1a09c..ade32a6f444 100644
754791
--- a/src/include/optimizer/pla 2851 nmain.h
755792
+++ b/src/include/optimizer/planmain.h
756793
@@ -24,6 +24,12 @@ extern PGDLLIMPORT double cursor_tuple_fraction;
@@ -767,7 +804,7 @@ index c4f61c1a09..ade32a6f44 100644
767804
* prototypes for plan/planmain.c
768805
*/
769806
diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h
770-
index 8f3d73edfb..91537e2325 100644
807+
index 8f3d73edfb2..91537e23252 100644
771808
--- a/src/include/utils/selfuncs.h
772809
+++ b/src/include/utils/selfuncs.h
773810
@@ -144,6 +144,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root,

0 commit comments

Comments
 (0)
0