11#include "pathman.h"
2+ #include "miscadmin.h"
23#include "executor/spi.h"
34#include "catalog/pg_type.h"
45#include "catalog/pg_class.h"
@@ -109,12 +110,15 @@ load_relations_hashtable(bool reinitialize)
109110
110111for (i = 0 ;i < proc ;i ++ )
111112{
113+ RelationKey key ;
112114HeapTuple tuple = tuptable -> vals [i ];
113115int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
114116
117+ key .dbid = MyDatabaseId ;
118+ key .relid = oid ;
115119prel = (PartRelationInfo * )
116- hash_search (relations , (const void * )& oid ,HASH_ENTER ,NULL );
117- prel -> oid = oid ;
120+ hash_search (relations , (const void * )& key ,HASH_ENTER ,NULL );
121+
118122prel -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
119123prel -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
120124prel -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
@@ -129,16 +133,13 @@ load_relations_hashtable(bool reinitialize)
129133{
130134Oid oid = (int )lfirst_int (lc );
131135
132- prel = (PartRelationInfo * )
133- hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
134-
136+ prel = get_pathman_relation_info (oid ,NULL );
135137switch (prel -> parttype )
136138{
137139case PT_RANGE :
138140if (reinitialize && prel -> children .length > 0 )
139141{
140- RangeRelation * rangerel = (RangeRelation * )
141- hash_search (range_restrictions , (void * )& oid ,HASH_FIND ,NULL );
142+ RangeRelation * rangerel = get_pathman_range_relation (oid ,NULL );
142143free_dsm_array (& prel -> children );
143144free_dsm_array (& rangerel -> ranges );
144145prel -> children_count = 0 ;
@@ -164,14 +165,14 @@ create_relations_hashtable()
164165HASHCTL ctl ;
165166
166167memset (& ctl ,0 ,sizeof (ctl ));
167- ctl .keysize = sizeof (int );
168+ ctl .keysize = sizeof (RelationKey );
168169ctl .entrysize = sizeof (PartRelationInfo );
169170
170171/* Already exists, recreate */
171172if (relations != NULL )
172173hash_destroy (relations );
173174
174- relations = ShmemInitHash ("Partitioning relation info" ,1024 ,& ctl ,HASH_ELEM );
175+ relations = ShmemInitHash ("Partitioning relation info" ,1024 ,& ctl ,HASH_ELEM | HASH_BLOBS );
175176}
176177
177178/*
@@ -199,8 +200,7 @@ load_check_constraints(Oid parent_oid)
199200// "where inhparent = %d and contype='c'";
200201// char *query;
201202
202- prel = (PartRelationInfo * )
203- hash_search (relations , (const void * )& parent_oid ,HASH_FIND ,& found );
203+ prel = get_pathman_relation_info (parent_oid ,NULL );
204204
205205/* Skip if already loaded */
206206if (prel -> children .length > 0 )
@@ -236,8 +236,12 @@ load_check_constraints(Oid parent_oid)
236236
237237if (prel -> parttype == PT_RANGE )
238238{
239+ RelationKey key ;
240+ key .dbid = MyDatabaseId ;
241+ key .relid = parent_oid ;
242+
239243rangerel = (RangeRelation * )
240- hash_search (range_restrictions , (void * )& parent_oid ,HASH_ENTER ,& found );
244+ hash_search (range_restrictions , (void * )& key ,HASH_ENTER ,& found );
241245
242246alloc_dsm_array (& rangerel -> ranges ,sizeof (RangeEntry ),proc );
243247ranges = (RangeEntry * )dsm_array_get_pointer (& rangerel -> ranges );
@@ -314,9 +318,13 @@ load_check_constraints(Oid parent_oid)
314318{
315319if (ranges [i ].max > ranges [i + 1 ].min )
316320{
321+ RelationKey key ;
322+ key .dbid = MyDatabaseId ;
323+ key .relid = parent_oid ;
324+
317325elog (WARNING ,"Partitions %u and %u overlap. Disabling pathman for relation %u..." ,
318326ranges [i ].child_oid ,ranges [i + 1 ].child_oid ,parent_oid );
319- hash_search (relations , (const void * )& parent_oid ,HASH_REMOVE ,& found );
327+ hash_search (relations , (const void * )& key ,HASH_REMOVE ,& found );
320328}
321329}
322330}
@@ -450,7 +458,7 @@ create_range_restrictions_hashtable()
450458HASHCTL ctl ;
451459
452460memset (& ctl ,0 ,sizeof (ctl ));
453- ctl .keysize = sizeof (int );
461+ ctl .keysize = sizeof (RelationKey );
454462ctl .entrysize = sizeof (RangeRelation );
455463range_restrictions = ShmemInitHash ("pg_pathman range restrictions" ,
4564641024 ,& ctl ,HASH_ELEM |HASH_BLOBS );
@@ -464,9 +472,12 @@ remove_relation_info(Oid relid)
464472{
465473PartRelationInfo * prel ;
466474RangeRelation * rangerel ;
475+ RelationKey key ;
476+
477+ key .dbid = MyDatabaseId ;
478+ key .relid = relid ;
467479
468- prel = (PartRelationInfo * )
469- hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
480+ prel = get_pathman_relation_info (relid ,NULL );
470481
471482/* If there is nothing to remove then just return */
472483if (!prel )
@@ -479,11 +490,10 @@ remove_relation_info(Oid relid)
479490free_dsm_array (& prel -> children );
480491break ;
481492case PT_RANGE :
482- rangerel = (RangeRelation * )
483- hash_search (range_restrictions , (const void * )& relid ,HASH_FIND ,0 );
493+ rangerel = get_pathman_range_relation (relid ,NULL );
484494free_dsm_array (& rangerel -> ranges );
485495free_dsm_array (& prel -> children );
486- hash_search (range_restrictions , (const void * )& relid ,HASH_REMOVE ,0 );
496+ hash_search (range_restrictions , (const void * )& key ,HASH_REMOVE ,0 );
487497break ;
488498}
489499prel -> children_count = 0 ;