14
14
init (void )
15
15
{
16
16
initialization_needed = false;
17
+ create_dsm_segment (32 );
17
18
load_part_relations_hashtable ();
18
- // load_hash_restrictions_hashtable();
19
- // load_range_restrictions_hashtable();
20
19
}
21
20
22
21
void
@@ -30,57 +29,65 @@ load_part_relations_hashtable()
30
29
List * part_oids = NIL ;
31
30
ListCell * lc ;
32
31
33
- SPI_connect ();
34
- ret = SPI_exec ("SELECT pg_class.relfilenode, pg_attribute.attnum, pg_pathman_rels.parttype, pg_attribute.atttypid "
35
- "FROM pg_pathman_rels "
36
- "JOIN pg_class ON pg_class.relname = pg_pathman_rels.relname "
37
- "JOIN pg_attribute ON pg_attribute.attname = pg_pathman_rels.attname "
38
- "AND attrelid = pg_class.relfilenode" , 0 );
39
- proc = SPI_processed ;
32
+ LWLockAcquire (load_config_lock , LW_EXCLUSIVE );
40
33
41
- if (ret > 0 && SPI_tuptable != NULL )
34
+ /* if hashtable is empty */
35
+ if (hash_get_num_entries (relations ) == 0 )
42
36
{
43
- TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
44
- SPITupleTable * tuptable = SPI_tuptable ;
45
-
46
- for (i = 0 ; i < proc ; i ++ )
37
+ SPI_connect ();
38
+ ret = SPI_exec ("SELECT pg_class.relfilenode, pg_attribute.attnum, pg_pathman_rels.parttype, pg_attribute.atttypid "
39
+ "FROM pg_pathman_rels "
40
+ "JOIN pg_class ON pg_class.relname = pg_pathman_rels.relname "
41
+ "JOIN pg_attribute ON pg_attribute.attname = pg_pathman_rels.attname "
42
+ "AND attrelid = pg_class.relfilenode" , 0 );
43
+ proc = SPI_processed ;
44
+
45
+ if (ret > 0 && SPI_tuptable != NULL )
47
46
{
48
- HeapTuple tuple = tuptable -> vals [i ];
47
+ TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
48
+ SPITupleTable * tuptable = SPI_tuptable ;
49
49
50
- int oid = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 1 , & isnull ));
51
- prinfo = (PartRelationInfo * )
52
- hash_search (relations , (const void * )& oid , HASH_ENTER , NULL );
53
- prinfo -> oid = oid ;
54
- prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 2 , & isnull ));
55
- prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 3 , & isnull ));
56
- prinfo -> atttype = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 4 , & isnull ));
50
+ for (i = 0 ; i < proc ; i ++ )
51
+ {
52
+ HeapTuple tuple = tuptable -> vals [i ];
53
+
54
+ int oid = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 1 , & isnull ));
55
+ prinfo = (PartRelationInfo * )
56
+ hash_search (relations , (const void * )& oid , HASH_ENTER , NULL );
57
+ prinfo -> oid = oid ;
58
+ prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 2 , & isnull ));
59
+ prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 3 , & isnull ));
60
+ prinfo -> atttype = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 4 , & isnull ));
57
61
58
- part_oids = lappend_int (part_oids , oid );
62
+ part_oids = lappend_int (part_oids , oid );
59
63
60
- /* children will be filled in later */
61
- // prinfo->children = NIL;
64
+ /* children will be filled in later */
65
+ // prinfo->children = NIL;
66
+ }
62
67
}
63
- }
64
68
65
- /* load children information */
66
- foreach (lc , part_oids )
67
- {
68
- Oid oid = (int ) lfirst_int (lc );
69
+ /* load children information */
70
+ foreach (lc , part_oids )
71
+ {
72
+ Oid oid = (int ) lfirst_int (lc );
69
73
70
- prinfo = (PartRelationInfo * )
71
- hash_search (relations , (const void * )& oid , HASH_FIND , NULL );
74
+ prinfo = (PartRelationInfo * )
75
+ hash_search (relations , (const void * )& oid , HASH_FIND , NULL );
72
76
73
- switch (prinfo -> parttype )
74
- {
75
- case PT_RANGE :
76
- load_range_restrictions (oid );
77
- break ;
78
- case PT_HASH :
79
- load_hash_restrictions (oid );
80
- break ;
77
+ switch (prinfo -> parttype )
78
+ {
79
+ case PT_RANGE :
80
+ load_range_restrictions (oid );
81
+ break ;
82
+ case PT_HASH :
83
+ load_hash_restrictions (oid );
84
+ break ;
85
+ }
81
86
}
87
+ SPI_finish ();
82
88
}
83
- SPI_finish ();
89
+
90
+ LWLockRelease (load_config_lock );
84
91
}
85
92
86
93
void
@@ -97,8 +104,9 @@ create_part_relations_hashtable()
97
104
hash_destroy (relations );
98
105
99
106
relations = ShmemInitHash ("Partitioning relation info" ,
100
- 16 , 16 ,
101
- & ctl , HASH_ELEM | HASH_BLOBS );
107
+ 32 , 32 ,
108
+ & ctl , HASH_ELEM );
109
+ // &ctl, HASH_ELEM | HASH_BLOBS);
102
110
}
103
111
104
112
void
@@ -137,6 +145,11 @@ load_hash_restrictions(Oid parent_oid)
137
145
{
138
146
TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
139
147
SPITupleTable * tuptable = SPI_tuptable ;
148
+ Oid * children ;
149
+
150
+ /* allocate an array of children Oids */
151
+ alloc_dsm_array (& prel -> children , sizeof (Oid ), proc );
152
+ children = (Oid * ) dsm_array_get_pointer (& prel -> children );
140
153
141
154
for (i = 0 ; i < proc ; i ++ )
142
155
{
@@ -151,7 +164,8 @@ load_hash_restrictions(Oid parent_oid)
151
164
hashrel -> child_oid = child_oid ;
152
165
153
166
/* appending children to PartRelationInfo */
154
- prel -> children [prel -> children_count ++ ] = child_oid ;
167
+ // prel->children[prel->children_count++] = child_oid;
168
+ children [prel -> children_count ++ ] = child_oid ;
155
169
}
156
170
}
157
171
@@ -225,11 +239,19 @@ load_range_restrictions(Oid parent_oid)
225
239
{
226
240
TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
227
241
SPITupleTable * tuptable = SPI_tuptable ;
242
+ Oid * children ;
243
+ RangeEntry * ranges ;
228
244
229
245
rangerel = (RangeRelation * )
230
246
hash_search (range_restrictions , (void * ) & parent_oid , HASH_ENTER , & found );
231
247
rangerel -> nranges = 0 ;
232
248
249
+ alloc_dsm_array (& prel -> children , sizeof (Oid ), proc );
250
+ children = (Oid * ) dsm_array_get_pointer (& prel -> children );
251
+
252
+ alloc_dsm_array (& rangerel -> ranges , sizeof (RangeEntry ), proc );
253
+ ranges = (RangeEntry * ) dsm_array_get_pointer (& rangerel -> ranges );
254
+
233
255
for (i = 0 ; i < proc ; i ++ )
234
256
{
235
257
Datum min ;
@@ -279,22 +301,9 @@ load_range_restrictions(Oid parent_oid)
279
301
break ;
280
302
}
281
303
282
- // re.min = SPI_getbinval(tuple, tupdesc, 3, &arg1_isnull);
283
- // re.max = SPI_getbinval(tuple, tupdesc, 4, &arg2_isnull);
284
- // // prel->atttype = AT_INT;
285
-
286
- // if (arg1_isnull || arg2_isnull)
287
- // {
288
- // re.min = SPI_getbinval(tuple, tupdesc, 5, &arg1_isnull);
289
- // re.max = SPI_getbinval(tuple, tupdesc, 6, &arg2_isnull);
290
- // // prel->atttype = AT_DATE;
291
-
292
- // if (arg1_isnull || arg2_isnull)
293
- // ereport(ERROR, (errmsg("Range relation should be of type either INTEGER or DATE")));
294
- // }
295
- rangerel -> ranges [rangerel -> nranges ++ ] = re ;
296
-
297
- prel -> children [prel -> children_count ++ ] = re .child_oid ;
304
+ ranges [rangerel -> nranges ++ ] = re ;
305
+ // prel->children[prel->children_count++] = re.child_oid;
306
+ children [prel -> children_count ++ ] = re .child_oid ;
298
307
}
299
308
}
300
309
0 commit comments