3838#include "utils/snapmgr.h"
3939
4040
41+ /* Help user in case of emergency */
42+ #define INIT_ERROR_HINT "pg_pathman will be disabled to allow you to resolve this issue"
43+
4144/* Initial size of 'partitioned_rels' table */
4245#define PART_RELS_SIZE 10
4346#define CHILD_FACTOR 500
4447
48+
4549/* Storage for PartRelationInfos */
46- HTAB * partitioned_rels = NULL ;
50+ HTAB * partitioned_rels = NULL ;
4751
4852/* Storage for PartParentInfos */
49- HTAB * parent_cache = NULL ;
53+ HTAB * parent_cache = NULL ;
5054
51- bool initialization_needed = true;
52- static bool relcache_callback_needed = true;
53-
54- /* Help user in case of emergency */
55- #define INIT_ERROR_HINT "pg_pathman will be disabled to allow you fix this"
55+ /* pg_pathman's init status */
56+ PathmanInitState pg_pathman_init_state ;
5657
58+ /* Shall we install new relcache callback? */
59+ static bool relcache_callback_needed = true;
5760
61+ /* Functions for various local caches */
5862static bool init_pathman_relation_oids (void );
5963static void fini_pathman_relation_oids (void );
6064static void init_local_cache (void );
@@ -81,6 +85,41 @@ static bool read_opexpr_const(const OpExpr *opexpr,
8185static int oid_cmp (const void * p1 , const void * p2 );
8286
8387
88+ /*
89+ * Save and restore main init state.
90+ */
91+
92+ void
93+ save_pathman_init_state (PathmanInitState * temp_init_state )
94+ {
95+ * temp_init_state = pg_pathman_init_state ;
96+ }
97+
98+ void
99+ restore_pathman_init_state (const PathmanInitState * temp_init_state )
100+ {
101+ pg_pathman_init_state = * temp_init_state ;
102+ }
103+
104+ /*
105+ * Create main GUC.
106+ */
107+ void
108+ init_main_pathman_toggle (void )
109+ {
110+ /* Main toggle, load_config() will enable it */
111+ DefineCustomBoolVariable ("pg_pathman.enable" ,
112+ "Enables pg_pathman's optimizations during the planner stage" ,
113+ NULL ,
114+ & pg_pathman_init_state .pg_pathman_enable ,
115+ true,
116+ PGC_USERSET ,
117+ 0 ,
118+ NULL ,
119+ pg_pathman_enable_assign_hook ,
120+ NULL );
121+ }
122+
84123/*
85124 * Create local PartRelationInfo cache & load pg_pathman's config.
86125 * Return true on success. May occasionally emit ERROR.
@@ -111,7 +150,7 @@ load_config(void)
111150 }
112151
113152 /* Mark pg_pathman as initialized */
114- initialization_needed = false;
153+ pg_pathman_init_state . initialization_needed = false;
115154
116155 elog (DEBUG2 , "pg_pathman's config has been loaded successfully [%u]" , MyProcPid );
117156
@@ -131,7 +170,7 @@ unload_config(void)
131170 fini_local_cache ();
132171
133172 /* Mark pg_pathman as uninitialized */
134- initialization_needed = true;
173+ pg_pathman_init_state . initialization_needed = true;
135174
136175 elog (DEBUG2 , "pg_pathman's config has been unloaded successfully [%u]" , MyProcPid );
137176}
@@ -539,7 +578,6 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
539578 heap_deform_tuple (htup , RelationGetDescr (rel ), values , isnull );
540579
541580 /* Perform checks for non-NULL columns */
542- Assert (!isnull [Anum_pathman_config_id - 1 ]);
543581 Assert (!isnull [Anum_pathman_config_partrel - 1 ]);
544582 Assert (!isnull [Anum_pathman_config_attname - 1 ]);
545583 Assert (!isnull [Anum_pathman_config_parttype - 1 ]);
0 commit comments