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"
@@ -108,12 +109,15 @@ load_relations_hashtable(bool reinitialize)
108109
109110for (i = 0 ;i < proc ;i ++ )
110111{
112+ RelationKey key ;
111113HeapTuple tuple = tuptable -> vals [i ];
112114int oid = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,1 ,& isnull ));
113115
116+ key .dbid = MyDatabaseId ;
117+ key .relid = oid ;
114118prel = (PartRelationInfo * )
115- hash_search (relations , (const void * )& oid ,HASH_ENTER ,NULL );
116- prel -> oid = oid ;
119+ hash_search (relations , (const void * )& key ,HASH_ENTER ,NULL );
120+
117121prel -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
118122prel -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
119123prel -> atttype = DatumGetObjectId (SPI_getbinval (tuple ,tupdesc ,4 ,& isnull ));
@@ -128,16 +132,13 @@ load_relations_hashtable(bool reinitialize)
128132{
129133Oid oid = (int )lfirst_int (lc );
130134
131- prel = (PartRelationInfo * )
132- hash_search (relations , (const void * )& oid ,HASH_FIND ,NULL );
133-
135+ prel = get_pathman_relation_info (oid ,NULL );
134136switch (prel -> parttype )
135137{
136138case PT_RANGE :
137139if (reinitialize && prel -> children .length > 0 )
138140{
139- RangeRelation * rangerel = (RangeRelation * )
140- hash_search (range_restrictions , (void * )& oid ,HASH_FIND ,NULL );
141+ RangeRelation * rangerel = get_pathman_range_relation (oid ,NULL );
141142free_dsm_array (& prel -> children );
142143free_dsm_array (& rangerel -> ranges );
143144prel -> children_count = 0 ;
@@ -163,14 +164,14 @@ create_relations_hashtable()
163164HASHCTL ctl ;
164165
165166memset (& ctl ,0 ,sizeof (ctl ));
166- ctl .keysize = sizeof (int );
167+ ctl .keysize = sizeof (RelationKey );
167168ctl .entrysize = sizeof (PartRelationInfo );
168169
169170/* Already exists, recreate */
170171if (relations != NULL )
171172hash_destroy (relations );
172173
173- relations = ShmemInitHash ("Partitioning relation info" ,1024 ,& ctl ,HASH_ELEM );
174+ relations = ShmemInitHash ("Partitioning relation info" ,1024 ,& ctl ,HASH_ELEM | HASH_BLOBS );
174175}
175176
176177/*
@@ -191,8 +192,7 @@ load_check_constraints(Oid parent_oid)
191192bool nulls [1 ]= {false};
192193vals [0 ]= Int32GetDatum (parent_oid );
193194
194- prel = (PartRelationInfo * )
195- hash_search (relations , (const void * )& parent_oid ,HASH_FIND ,& found );
195+ prel = get_pathman_relation_info (parent_oid ,NULL );
196196
197197/* Skip if already loaded */
198198if (prel -> children .length > 0 )
@@ -219,8 +219,12 @@ load_check_constraints(Oid parent_oid)
219219
220220if (prel -> parttype == PT_RANGE )
221221{
222+ RelationKey key ;
223+ key .dbid = MyDatabaseId ;
224+ key .relid = parent_oid ;
225+
222226rangerel = (RangeRelation * )
223- hash_search (range_restrictions , (void * )& parent_oid ,HASH_ENTER ,& found );
227+ hash_search (range_restrictions , (void * )& key ,HASH_ENTER ,& found );
224228
225229alloc_dsm_array (& rangerel -> ranges ,sizeof (RangeEntry ),proc );
226230ranges = (RangeEntry * )dsm_array_get_pointer (& rangerel -> ranges );
@@ -297,9 +301,13 @@ load_check_constraints(Oid parent_oid)
297301{
298302if (ranges [i ].max > ranges [i + 1 ].min )
299303{
304+ RelationKey key ;
305+ key .dbid = MyDatabaseId ;
306+ key .relid = parent_oid ;
307+
300308elog (WARNING ,"Partitions %u and %u overlap. Disabling pathman for relation %u..." ,
301309ranges [i ].child_oid ,ranges [i + 1 ].child_oid ,parent_oid );
302- hash_search (relations , (const void * )& parent_oid ,HASH_REMOVE ,& found );
310+ hash_search (relations , (const void * )& key ,HASH_REMOVE ,& found );
303311}
304312}
305313}
@@ -433,7 +441,7 @@ create_range_restrictions_hashtable()
433441HASHCTL ctl ;
434442
435443memset (& ctl ,0 ,sizeof (ctl ));
436- ctl .keysize = sizeof (int );
444+ ctl .keysize = sizeof (RelationKey );
437445ctl .entrysize = sizeof (RangeRelation );
438446range_restrictions = ShmemInitHash ("pg_pathman range restrictions" ,
4394471024 ,& ctl ,HASH_ELEM |HASH_BLOBS );
@@ -447,9 +455,12 @@ remove_relation_info(Oid relid)
447455{
448456PartRelationInfo * prel ;
449457RangeRelation * rangerel ;
458+ RelationKey key ;
459+
460+ key .dbid = MyDatabaseId ;
461+ key .relid = relid ;
450462
451- prel = (PartRelationInfo * )
452- hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
463+ prel = get_pathman_relation_info (relid ,NULL );
453464
454465/* If there is nothing to remove then just return */
455466if (!prel )
@@ -462,11 +473,10 @@ remove_relation_info(Oid relid)
462473free_dsm_array (& prel -> children );
463474break ;
464475case PT_RANGE :
465- rangerel = (RangeRelation * )
466- hash_search (range_restrictions , (const void * )& relid ,HASH_FIND ,0 );
476+ rangerel = get_pathman_range_relation (relid ,NULL );
467477free_dsm_array (& rangerel -> ranges );
468478free_dsm_array (& prel -> children );
469- hash_search (range_restrictions , (const void * )& relid ,HASH_REMOVE ,0 );
479+ hash_search (range_restrictions , (const void * )& key ,HASH_REMOVE ,0 );
470480break ;
471481}
472482prel -> children_count = 0 ;