1616
1717HTAB * relations = NULL ;
1818HTAB * range_restrictions = NULL ;
19- // bool *config_loaded = NULL;
2019bool initialization_needed = true;
2120
2221typedef struct ShmemConfig
@@ -26,6 +25,7 @@ typedef struct ShmemConfig
2625ShmemConfig * shmem_cfg ;
2726
2827static FmgrInfo * qsort_type_cmp_func ;
28+ static bool globalByVal ;
2929
3030static bool validate_range_constraint (Expr * ,PartRelationInfo * ,Datum * ,Datum * );
3131static bool validate_hash_constraint (Expr * expr ,PartRelationInfo * prel ,int * hash );
@@ -40,7 +40,6 @@ init_shmem_config()
4040shmem_cfg = (ShmemConfig * )
4141ShmemInitStruct ("pathman shmem config" ,sizeof (ShmemConfig ),& found );
4242shmem_cfg -> config_loaded = false;
43- // *config_loaded = false;
4443}
4544
4645/*
@@ -60,7 +59,6 @@ load_config(void)
6059LWLockAcquire (load_config_lock ,LW_EXCLUSIVE );
6160load_relations_hashtable (new_segment_created );
6261LWLockRelease (load_config_lock );
63- // *config_loaded = true;
6462shmem_cfg -> config_loaded = true;
6563}
6664}
@@ -247,6 +245,7 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
247245
248246if (prel -> parttype == PT_RANGE )
249247{
248+ TypeCacheEntry * tce ;
250249RelationKey key ;
251250key .dbid = MyDatabaseId ;
252251key .relid = parent_oid ;
@@ -256,6 +255,9 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
256255
257256alloc_dsm_array (& rangerel -> ranges ,sizeof (RangeEntry ),proc );
258257ranges = (RangeEntry * )dsm_array_get_pointer (& rangerel -> ranges );
258+
259+ tce = lookup_type_cache (prel -> atttype ,0 );
260+ rangerel -> by_val = tce -> typbyval ;
259261}
260262
261263for (i = 0 ;i < proc ;i ++ )
@@ -290,10 +292,19 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
290292continue ;
291293}
292294
295+ /* If datum is referenced by val then just assign */
296+ if (rangerel -> by_val )
297+ {
298+ re .min = min ;
299+ re .max = max ;
300+ }
301+ /* else copy the memory by pointer */
302+ else
303+ {
304+ memcpy (& re .min ,DatumGetPointer (min ),sizeof (re .min ));
305+ memcpy (& re .max ,DatumGetPointer (max ),sizeof (re .max ));
306+ }
293307re .child_oid = con -> conrelid ;
294- re .min = min ;
295- re .max = max ;
296-
297308ranges [i ]= re ;
298309break ;
299310
@@ -313,11 +324,13 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
313324if (prel -> parttype == PT_RANGE )
314325{
315326TypeCacheEntry * tce ;
327+ bool byVal = rangerel -> by_val ;
316328
317329/* Sort ascending */
318330tce = lookup_type_cache (prel -> atttype ,
319331TYPECACHE_CMP_PROC |TYPECACHE_CMP_PROC_FINFO );
320332qsort_type_cmp_func = & tce -> cmp_proc_finfo ;
333+ globalByVal = byVal ;
321334qsort (ranges ,proc ,sizeof (RangeEntry ),cmp_range_entries );
322335
323336/* Copy oids to prel */
@@ -327,7 +340,12 @@ load_check_constraints(Oid parent_oid, Snapshot snapshot)
327340/* Check if some ranges overlap */
328341for (i = 0 ;i < proc - 1 ;i ++ )
329342{
330- if (ranges [i ].max > ranges [i + 1 ].min )
343+ Datum cur_upper = PATHMAN_GET_DATUM (ranges [i ].max ,byVal );
344+ Datum next_lower = PATHMAN_GET_DATUM (ranges [i + 1 ].min ,byVal );
345+ bool overlap = FunctionCall2 (qsort_type_cmp_func ,next_lower ,cur_upper )> 0 ;
346+
347+ if (overlap )
348+ // if (ranges[i].max > ranges[i+1].min)
331349{
332350RelationKey key ;
333351key .dbid = MyDatabaseId ;
@@ -350,7 +368,9 @@ cmp_range_entries(const void *p1, const void *p2)
350368const RangeEntry * v1 = (const RangeEntry * )p1 ;
351369const RangeEntry * v2 = (const RangeEntry * )p2 ;
352370
353- return FunctionCall2 (qsort_type_cmp_func ,v1 -> min ,v2 -> min );
371+ return FunctionCall2 (qsort_type_cmp_func ,
372+ PATHMAN_GET_DATUM (v1 -> min ,globalByVal ),
373+ PATHMAN_GET_DATUM (v2 -> min ,globalByVal ));
354374}
355375
356376/*