@@ -53,6 +53,8 @@ bool initialization_needed = true;
5353static bool relcache_callback_needed = true;
5454
5555
56+ static bool init_pathman_relation_oids (void );
57+ static void fini_pathman_relation_oids (void );
5658static void init_local_cache (void );
5759static void fini_local_cache (void );
5860static void read_pathman_config (void );
@@ -79,12 +81,22 @@ static int oid_cmp(const void *p1, const void *p2);
7981
8082/*
8183 * Create local PartRelationInfo cache & load pg_pathman's config.
84+ * Return true on success. May occasionally emit ERROR.
8285 */
83- void
86+ bool
8487load_config (void )
8588{
86- /* Cache PATHMAN_CONFIG relation's Oid */
87- pathman_config_relid = get_relname_relid (PATHMAN_CONFIG , get_pathman_schema ());
89+ /*
90+ * Try to cache important relids.
91+ *
92+ * Once CREATE EXTENSION stmt is processed, get_pathman_schema()
93+ * function starts returning perfectly valid schema Oid, which
94+ * means we have to check that *ALL* pg_pathman's relations' Oids
95+ * have been cached properly. Only then can we assume that
96+ * initialization is not needed anymore.
97+ */
98+ if (!init_pathman_relation_oids ())
99+ return false; /* remain 'uninitialized', exit before creating main caches */
88100
89101 init_local_cache (); /* create 'partitioned_rels' hash table */
90102 read_pathman_config (); /* read PATHMAN_CONFIG table & fill cache */
@@ -100,6 +112,8 @@ load_config(void)
100112 initialization_needed = false;
101113
102114 elog (DEBUG2 , "pg_pathman's config has been loaded successfully [%u]" , MyProcPid );
115+
116+ return true;
103117}
104118
105119/*
@@ -108,10 +122,11 @@ load_config(void)
108122void
109123unload_config (void )
110124{
111- /* Don't forget to reset cached PATHMAN_CONFIG relation 's Oid */
112- pathman_config_relid = InvalidOid ;
125+ /* Don't forget to reset pg_pathman 's cached relids */
126+ fini_pathman_relation_oids () ;
113127
114- fini_local_cache (); /* destroy 'partitioned_rels' hash table */
128+ /* Destroy 'partitioned_rels' & 'parent_cache' hash tables */
129+ fini_local_cache ();
115130
116131 /* Mark pg_pathman as uninitialized */
117132 initialization_needed = true;
@@ -128,6 +143,40 @@ estimate_pathman_shmem_size(void)
128143 return estimate_dsm_config_size () + MAXALIGN (sizeof (PathmanState ));
129144}
130145
146+ /*
147+ * Cache *all* important pg_pathman's relids at once.
148+ * We should NOT rely on any previously cached values.
149+ */
150+ static bool
151+ init_pathman_relation_oids (void )
152+ {
153+ Oid schema = get_pathman_schema ();
154+ Assert (schema != InvalidOid );
155+
156+ /* Cache PATHMAN_CONFIG relation's Oid */
157+ pathman_config_relid = get_relname_relid (PATHMAN_CONFIG , schema );
158+ /* NOTE: add more relations to be cached right here ^^^ */
159+
160+ /* Return false if *any* relation doesn't exist yet */
161+ if (pathman_config_relid == InvalidOid )
162+ {
163+ return false;
164+ }
165+
166+ /* Everything is fine, proceed */
167+ return true;
168+ }
169+
170+ /*
171+ * Forget *all* pg_pathman's cached relids.
172+ */
173+ static void
174+ fini_pathman_relation_oids (void )
175+ {
176+ pathman_config_relid = InvalidOid ;
177+ /* NOTE: add more relations to be forgotten right here ^^^ */
178+ }
179+
131180/*
132181 * Initialize per-process resources.
133182 */
0 commit comments