Skip to content

Load configuration in post_parse_analyze hook #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions pg_pathman.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "optimizer/planner.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/cost.h"
#include "parser/analyze.h"
#include "parser/parsetree.h"
#include "utils/hsearch.h"
#include "utils/tqual.h"
Expand Down Expand Up @@ -56,6 +57,7 @@ typedef struct
/* Original hooks */
static set_rel_pathlist_hook_type set_rel_pathlist_hook_original = NULL;
static shmem_startup_hook_type shmem_startup_hook_original = NULL;
static post_parse_analyze_hook_type post_parse_analyze_hook_original = NULL;
static planner_hook_type planner_hook_original = NULL;

/* pg module functions */
Expand All @@ -65,6 +67,7 @@ void _PG_fini(void);
/* Hook functions */
static void pathman_shmem_startup(void);
static void pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte);
void pathman_post_parse_analysis_hook(ParseState *pstate, Query *query);
static PlannedStmt * pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams);

/* Utility functions */
Expand Down Expand Up @@ -135,6 +138,8 @@ _PG_init(void)
set_rel_pathlist_hook = pathman_set_rel_pathlist_hook;
shmem_startup_hook_original = shmem_startup_hook;
shmem_startup_hook = pathman_shmem_startup;
post_parse_analyze_hook_original = post_parse_analyze_hook;
post_parse_analyze_hook = pathman_post_parse_analysis_hook;
planner_hook_original = planner_hook;
planner_hook = pathman_planner_hook;
}
Expand All @@ -144,6 +149,7 @@ _PG_fini(void)
{
set_rel_pathlist_hook = set_rel_pathlist_hook_original;
shmem_startup_hook = shmem_startup_hook_original;
post_parse_analyze_hook = post_parse_analyze_hook_original;
planner_hook = planner_hook_original;
}

Expand Down Expand Up @@ -186,6 +192,20 @@ get_cmp_func(Oid type1, Oid type2)
return cmp_func;
}

/*
* Post parse analysis hook. It makes sure the config is loaded before executing
* any statement, including utility commands
*/
void
pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
{
if (initialization_needed)
load_config();

if (post_parse_analyze_hook_original)
post_parse_analyze_hook_original(pstate, query);
}

/*
* Planner hook. It disables inheritance for tables that have been partitioned
* by pathman to prevent standart PostgreSQL partitioning mechanism from
Expand All @@ -197,11 +217,6 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
PlannedStmt *result;
ListCell *lc;

if (initialization_needed)
{
load_config();
}

inheritance_disabled = false;
switch(parse->commandType)
{
Expand Down