@@ -53,6 +53,8 @@ boolinitialization_needed = true;
53
53
static bool relcache_callback_needed = true;
54
54
55
55
56
+ static bool init_pathman_relation_oids (void );
57
+ static void fini_pathman_relation_oids (void );
56
58
static void init_local_cache (void );
57
59
static void fini_local_cache (void );
58
60
static void read_pathman_config (void );
@@ -79,12 +81,22 @@ static int oid_cmp(const void *p1, const void *p2);
79
81
80
82
/*
81
83
* Create local PartRelationInfo cache & load pg_pathman's config.
84
+ * Return true on success. May occasionally emit ERROR.
82
85
*/
83
- void
86
+ bool
84
87
load_config (void )
85
88
{
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 */
88
100
89
101
init_local_cache ();/* create 'partitioned_rels' hash table */
90
102
read_pathman_config ();/* read PATHMAN_CONFIG table & fill cache */
@@ -100,6 +112,8 @@ load_config(void)
100
112
initialization_needed = false;
101
113
102
114
elog (DEBUG2 ,"pg_pathman's config has been loaded successfully [%u]" ,MyProcPid );
115
+
116
+ return true;
103
117
}
104
118
105
119
/*
@@ -108,10 +122,11 @@ load_config(void)
108
122
void
109
123
unload_config (void )
110
124
{
111
- /* Don't forget to resetcached PATHMAN_CONFIG relation 'sOid */
112
- pathman_config_relid = InvalidOid ;
125
+ /* Don't forget to resetpg_pathman 'scached relids */
126
+ fini_pathman_relation_oids () ;
113
127
114
- fini_local_cache ();/* destroy 'partitioned_rels' hash table */
128
+ /* Destroy 'partitioned_rels' & 'parent_cache' hash tables */
129
+ fini_local_cache ();
115
130
116
131
/* Mark pg_pathman as uninitialized */
117
132
initialization_needed = true;
@@ -128,6 +143,40 @@ estimate_pathman_shmem_size(void)
128
143
return estimate_dsm_config_size ()+ MAXALIGN (sizeof (PathmanState ));
129
144
}
130
145
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
+
131
180
/*
132
181
* Initialize per-process resources.
133
182
*/