@@ -26,11 +26,13 @@ static int cmp_range_entries(const void *p1, const void *p2);
2626void
2727init (void )
2828{
29+ bool new_segment_created ;
30+
2931initialization_needed = false;
30- create_dsm_segment (32 );
32+ new_segment_created = init_dsm_segment (32 );
3133
3234LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
33- load_part_relations_hashtable ();
35+ load_part_relations_hashtable (new_segment_created );
3436LWLockRelease (load_config_lock );
3537}
3638
@@ -42,9 +44,9 @@ check_extension()
4244}
4345
4446void
45- load_part_relations_hashtable ()
47+ load_part_relations_hashtable (bool reinitialize )
4648{
47- PartRelationInfo * prinfo ;
49+ PartRelationInfo * prel ;
4850int ret ;
4951int i ;
5052int proc ;
@@ -78,12 +80,12 @@ load_part_relations_hashtable()
7880HeapTuple tuple = tuptable -> vals [i ];
7981int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
8082
81- prinfo = (PartRelationInfo * )
83+ prel = (PartRelationInfo * )
8284hash_search (relations , (const void * )& oid ,HASH_ENTER ,NULL );
83- prinfo -> oid = oid ;
84- prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
85- prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
86- prinfo -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
85+ prel -> oid = oid ;
86+ prel -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
87+ prel -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
88+ prel -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
8789
8890part_oids = lappend_int (part_oids ,oid );
8991
@@ -97,18 +99,31 @@ load_part_relations_hashtable()
9799{
98100Oid oid = (int )lfirst_int (lc );
99101
100- prinfo = (PartRelationInfo * )
102+ prel = (PartRelationInfo * )
101103hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
102104
103105// load_check_constraints(oid);
104106
105- switch (prinfo -> parttype )
107+ switch (prel -> parttype )
106108{
107109case PT_RANGE :
108110// load_range_restrictions(oid);
111+ if (reinitialize && prel -> children .length > 0 )
112+ {
113+ RangeRelation * rangerel = (RangeRelation * )
114+ hash_search (range_restrictions , (void * )& oid ,HASH_FIND ,NULL );
115+ free_dsm_array (& prel -> children );
116+ free_dsm_array (& rangerel -> ranges );
117+ prel -> children_count = 0 ;
118+ }
109119load_check_constraints (oid );
110120break ;
111121case PT_HASH :
122+ if (reinitialize && prel -> children .length > 0 )
123+ {
124+ free_dsm_array (& prel -> children );
125+ prel -> children_count = 0 ;
126+ }
112127load_hash_restrictions (oid );
113128break ;
114129}
@@ -242,6 +257,10 @@ load_check_constraints(Oid parent_oid)
242257prel = (PartRelationInfo * )
243258hash_search (relations , (const void * )& parent_oid ,HASH_FIND ,& found );
244259
260+ /* skip if already loaded */
261+ if (prel -> children .length > 0 )
262+ return ;
263+
245264// /* if already loaded then quit */
246265// if (prel->children_count > 0)
247266// return;
@@ -256,7 +275,7 @@ load_check_constraints(Oid parent_oid)
256275
257276if (ret > 0 && SPI_tuptable != NULL )
258277 {
259- TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
278+ // TupleDesc tupdesc = SPI_tuptable->tupdesc;
260279SPITupleTable * tuptable = SPI_tuptable ;
261280Oid * children ;
262281RangeEntry * ranges ;
@@ -265,7 +284,7 @@ load_check_constraints(Oid parent_oid)
265284
266285rangerel = (RangeRelation * )
267286hash_search (range_restrictions , (void * )& parent_oid ,HASH_ENTER ,& found );
268- rangerel -> nranges = 0 ;
287+ // rangerel->nranges = 0;
269288
270289alloc_dsm_array (& prel -> children ,sizeof (Oid ),proc );
271290children = (Oid * )dsm_array_get_pointer (& prel -> children );
@@ -304,15 +323,15 @@ load_check_constraints(Oid parent_oid)
304323re .min = min ;
305324re .max = max ;
306325
307- ranges [rangerel -> nranges ++ ]= re ;
326+ ranges [i ]= re ;
308327// children[prel->children_count++] = re.child_oid;
309328}
310329
311330/* sort ascending */
312- qsort (ranges ,rangerel -> nranges ,sizeof (RangeEntry ),cmp_range_entries );
331+ qsort (ranges ,proc ,sizeof (RangeEntry ),cmp_range_entries );
313332
314333/* copy oids to prel */
315- for (i = 0 ;i < rangerel -> nranges ;i ++ ,prel -> children_count ++ )
334+ for (i = 0 ;i < proc ;i ++ ,prel -> children_count ++ )
316335children [i ]= ranges [i ].child_oid ;
317336
318337/* TODO: check if some ranges overlap! */
@@ -324,8 +343,8 @@ load_check_constraints(Oid parent_oid)
324343static int
325344cmp_range_entries (const void * p1 ,const void * p2 )
326345{
327- RangeEntry * v1 = (const RangeEntry * )p1 ;
328- RangeEntry * v2 = (const RangeEntry * )p2 ;
346+ const RangeEntry * v1 = (const RangeEntry * )p1 ;
347+ const RangeEntry * v2 = (const RangeEntry * )p2 ;
329348
330349if (v1 -> min < v2 -> min )
331350return -1 ;
@@ -382,8 +401,8 @@ validate_range_constraint(Expr *expr, PartRelationInfo *prel, Datum *min, Datum
382401return false;
383402* max = ((Const * )right )-> constvalue ;
384403}
385- else
386- return false;
404+
405+ return false;
387406}
388407
389408/*