22
22
#include "optimizer/planner.h"
23
23
#include "optimizer/restrictinfo.h"
24
24
#include "optimizer/cost.h"
25
+ #include "parser/analyze.h"
25
26
#include "parser/parsetree.h"
26
27
#include "utils/hsearch.h"
27
28
#include "utils/tqual.h"
@@ -56,6 +57,7 @@ typedef struct
56
57
/* Original hooks */
57
58
static set_rel_pathlist_hook_type set_rel_pathlist_hook_original = NULL ;
58
59
static shmem_startup_hook_type shmem_startup_hook_original = NULL ;
60
+ static post_parse_analyze_hook_type post_parse_analyze_hook_original = NULL ;
59
61
static planner_hook_type planner_hook_original = NULL ;
60
62
61
63
/* pg module functions */
@@ -65,6 +67,7 @@ void _PG_fini(void);
65
67
/* Hook functions */
66
68
static void pathman_shmem_startup (void );
67
69
static void pathman_set_rel_pathlist_hook (PlannerInfo * root , RelOptInfo * rel , Index rti , RangeTblEntry * rte );
70
+ void pathman_post_parse_analysis_hook (ParseState * pstate , Query * query );
68
71
static PlannedStmt * pathman_planner_hook (Query * parse , int cursorOptions , ParamListInfo boundParams );
69
72
70
73
/* Utility functions */
@@ -135,6 +138,8 @@ _PG_init(void)
135
138
set_rel_pathlist_hook = pathman_set_rel_pathlist_hook ;
136
139
shmem_startup_hook_original = shmem_startup_hook ;
137
140
shmem_startup_hook = pathman_shmem_startup ;
141
+ post_parse_analyze_hook_original = post_parse_analyze_hook ;
142
+ post_parse_analyze_hook = pathman_post_parse_analysis_hook ;
138
143
planner_hook_original = planner_hook ;
139
144
planner_hook = pathman_planner_hook ;
140
145
}
@@ -144,6 +149,7 @@ _PG_fini(void)
144
149
{
145
150
set_rel_pathlist_hook = set_rel_pathlist_hook_original ;
146
151
shmem_startup_hook = shmem_startup_hook_original ;
152
+ post_parse_analyze_hook = post_parse_analyze_hook_original ;
147
153
planner_hook = planner_hook_original ;
148
154
}
149
155
@@ -186,6 +192,20 @@ get_cmp_func(Oid type1, Oid type2)
186
192
return cmp_func ;
187
193
}
188
194
195
+ /*
196
+ * Post parse analysis hook. It makes sure the config is loaded before executing
197
+ * any statement, including utility commands
198
+ */
199
+ void
200
+ pathman_post_parse_analysis_hook (ParseState * pstate , Query * query )
201
+ {
202
+ if (initialization_needed )
203
+ load_config ();
204
+
205
+ if (post_parse_analyze_hook_original )
206
+ post_parse_analyze_hook_original (pstate , query );
207
+ }
208
+
189
209
/*
190
210
* Planner hook. It disables inheritance for tables that have been partitioned
191
211
* by pathman to prevent standart PostgreSQL partitioning mechanism from
@@ -197,11 +217,6 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
197
217
PlannedStmt * result ;
198
218
ListCell * lc ;
199
219
200
- if (initialization_needed )
201
- {
202
- load_config ();
203
- }
204
-
205
220
inheritance_disabled = false;
206
221
switch (parse -> commandType )
207
222
{
0 commit comments