@@ -26,11 +26,13 @@ static int cmp_range_entries(const void *p1, const void *p2);
26
26
void
27
27
init (void )
28
28
{
29
+ bool new_segment_created ;
30
+
29
31
initialization_needed = false;
30
- create_dsm_segment (32 );
32
+ new_segment_created = init_dsm_segment (32 );
31
33
32
34
LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
33
- load_part_relations_hashtable ();
35
+ load_part_relations_hashtable (new_segment_created );
34
36
LWLockRelease (load_config_lock );
35
37
}
36
38
@@ -42,9 +44,9 @@ check_extension()
42
44
}
43
45
44
46
void
45
- load_part_relations_hashtable ()
47
+ load_part_relations_hashtable (bool reinitialize )
46
48
{
47
- PartRelationInfo * prinfo ;
49
+ PartRelationInfo * prel ;
48
50
int ret ;
49
51
int i ;
50
52
int proc ;
@@ -78,12 +80,12 @@ load_part_relations_hashtable()
78
80
HeapTuple tuple = tuptable -> vals [i ];
79
81
int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
80
82
81
- prinfo = (PartRelationInfo * )
83
+ prel = (PartRelationInfo * )
82
84
hash_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 ));
87
89
88
90
part_oids = lappend_int (part_oids ,oid );
89
91
@@ -97,18 +99,31 @@ load_part_relations_hashtable()
97
99
{
98
100
Oid oid = (int )lfirst_int (lc );
99
101
100
- prinfo = (PartRelationInfo * )
102
+ prel = (PartRelationInfo * )
101
103
hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
102
104
103
105
// load_check_constraints(oid);
104
106
105
- switch (prinfo -> parttype )
107
+ switch (prel -> parttype )
106
108
{
107
109
case PT_RANGE :
108
110
// 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
+ }
109
119
load_check_constraints (oid );
110
120
break ;
111
121
case PT_HASH :
122
+ if (reinitialize && prel -> children .length > 0 )
123
+ {
124
+ free_dsm_array (& prel -> children );
125
+ prel -> children_count = 0 ;
126
+ }
112
127
load_hash_restrictions (oid );
113
128
break ;
114
129
}
@@ -242,6 +257,10 @@ load_check_constraints(Oid parent_oid)
242
257
prel = (PartRelationInfo * )
243
258
hash_search (relations , (const void * )& parent_oid ,HASH_FIND ,& found );
244
259
260
+ /* skip if already loaded */
261
+ if (prel -> children .length > 0 )
262
+ return ;
263
+
245
264
// /* if already loaded then quit */
246
265
// if (prel->children_count > 0)
247
266
// return;
@@ -256,7 +275,7 @@ load_check_constraints(Oid parent_oid)
256
275
257
276
if (ret > 0 && SPI_tuptable != NULL )
258
277
{
259
- TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
278
+ // TupleDesc tupdesc = SPI_tuptable->tupdesc;
260
279
SPITupleTable * tuptable = SPI_tuptable ;
261
280
Oid * children ;
262
281
RangeEntry * ranges ;
@@ -265,7 +284,7 @@ load_check_constraints(Oid parent_oid)
265
284
266
285
rangerel = (RangeRelation * )
267
286
hash_search (range_restrictions , (void * )& parent_oid ,HASH_ENTER ,& found );
268
- rangerel -> nranges = 0 ;
287
+ // rangerel->nranges = 0;
269
288
270
289
alloc_dsm_array (& prel -> children ,sizeof (Oid ),proc );
271
290
children = (Oid * )dsm_array_get_pointer (& prel -> children );
@@ -304,15 +323,15 @@ load_check_constraints(Oid parent_oid)
304
323
re .min = min ;
305
324
re .max = max ;
306
325
307
- ranges [rangerel -> nranges ++ ]= re ;
326
+ ranges [i ]= re ;
308
327
// children[prel->children_count++] = re.child_oid;
309
328
}
310
329
311
330
/* sort ascending */
312
- qsort (ranges ,rangerel -> nranges ,sizeof (RangeEntry ),cmp_range_entries );
331
+ qsort (ranges ,proc ,sizeof (RangeEntry ),cmp_range_entries );
313
332
314
333
/* 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 ++ )
316
335
children [i ]= ranges [i ].child_oid ;
317
336
318
337
/* TODO: check if some ranges overlap! */
@@ -324,8 +343,8 @@ load_check_constraints(Oid parent_oid)
324
343
static int
325
344
cmp_range_entries (const void * p1 ,const void * p2 )
326
345
{
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 ;
329
348
330
349
if (v1 -> min < v2 -> min )
331
350
return -1 ;
@@ -382,8 +401,8 @@ validate_range_constraint(Expr *expr, PartRelationInfo *prel, Datum *min, Datum
382
401
return false;
383
402
* max = ((Const * )right )-> constvalue ;
384
403
}
385
- else
386
- return false;
404
+
405
+ return false;
387
406
}
388
407
389
408
/*