1414init (void )
1515{
1616initialization_needed = false;
17+ create_dsm_segment (32 );
1718load_part_relations_hashtable ();
18- // load_hash_restrictions_hashtable();
19- // load_range_restrictions_hashtable();
2019}
2120
2221void
@@ -30,57 +29,65 @@ load_part_relations_hashtable()
3029List * part_oids = NIL ;
3130ListCell * lc ;
3231
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 );
4033
41- if (ret > 0 && SPI_tuptable != NULL )
34+ /* if hashtable is empty */
35+ if (hash_get_num_entries (relations )== 0 )
4236{
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 )
4746{
48- HeapTuple tuple = tuptable -> vals [i ];
47+ TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
48+ SPITupleTable * tuptable = SPI_tuptable ;
4949
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 ));
5761
58- part_oids = lappend_int (part_oids ,oid );
62+ part_oids = lappend_int (part_oids ,oid );
5963
60- /* children will be filled in later */
61- // prinfo->children = NIL;
64+ /* children will be filled in later */
65+ // prinfo->children = NIL;
66+ }
6267}
63- }
6468
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 );
6973
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 );
7276
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+ }
8186}
87+ SPI_finish ();
8288}
83- SPI_finish ();
89+
90+ LWLockRelease (load_config_lock );
8491}
8592
8693void
@@ -97,8 +104,9 @@ create_part_relations_hashtable()
97104hash_destroy (relations );
98105
99106relations = 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);
102110}
103111
104112void
@@ -137,6 +145,11 @@ load_hash_restrictions(Oid parent_oid)
137145 {
138146TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
139147SPITupleTable * 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 );
140153
141154for (i = 0 ;i < proc ;i ++ )
142155 {
@@ -151,7 +164,8 @@ load_hash_restrictions(Oid parent_oid)
151164hashrel -> child_oid = child_oid ;
152165
153166/* 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 ;
155169 }
156170 }
157171
@@ -225,11 +239,19 @@ load_range_restrictions(Oid parent_oid)
225239 {
226240TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
227241SPITupleTable * tuptable = SPI_tuptable ;
242+ Oid * children ;
243+ RangeEntry * ranges ;
228244
229245rangerel = (RangeRelation * )
230246hash_search (range_restrictions , (void * )& parent_oid ,HASH_ENTER ,& found );
231247rangerel -> nranges = 0 ;
232248
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+
233255for (i = 0 ;i < proc ;i ++ )
234256 {
235257Datum min ;
@@ -279,22 +301,9 @@ load_range_restrictions(Oid parent_oid)
279301break ;
280302}
281303
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 ;
298307 }
299308 }
300309