1
1
#include "pathman.h"
2
+ #include "miscadmin.h"
2
3
#include "executor/spi.h"
3
4
#include "catalog/pg_type.h"
4
5
#include "catalog/pg_class.h"
@@ -108,12 +109,15 @@ load_relations_hashtable(bool reinitialize)
108
109
109
110
for (i = 0 ; i < proc ; i ++ )
110
111
{
112
+ RelationKey key ;
111
113
HeapTuple tuple = tuptable -> vals [i ];
112
114
int oid = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 1 , & isnull ));
113
115
116
+ key .dbid = MyDatabaseId ;
117
+ key .relid = oid ;
114
118
prel = (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
+
117
121
prel -> attnum = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 2 , & isnull ));
118
122
prel -> parttype = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 3 , & isnull ));
119
123
prel -> atttype = DatumGetObjectId (SPI_getbinval (tuple , tupdesc , 4 , & isnull ));
@@ -128,16 +132,13 @@ load_relations_hashtable(bool reinitialize)
128
132
{
129
133
Oid oid = (int ) lfirst_int (lc );
130
134
131
- prel = (PartRelationInfo * )
132
- hash_search (relations , (const void * )& oid , HASH_FIND , NULL );
133
-
135
+ prel = get_pathman_relation_info (oid , NULL );
134
136
switch (prel -> parttype )
135
137
{
136
138
case PT_RANGE :
137
139
if (reinitialize && prel -> children .length > 0 )
138
140
{
139
- RangeRelation * rangerel = (RangeRelation * )
140
- hash_search (range_restrictions , (void * ) & oid , HASH_FIND , NULL );
141
+ RangeRelation * rangerel = get_pathman_range_relation (oid , NULL );
141
142
free_dsm_array (& prel -> children );
142
143
free_dsm_array (& rangerel -> ranges );
143
144
prel -> children_count = 0 ;
@@ -163,14 +164,14 @@ create_relations_hashtable()
163
164
HASHCTL ctl ;
164
165
165
166
memset (& ctl , 0 , sizeof (ctl ));
166
- ctl .keysize = sizeof (int );
167
+ ctl .keysize = sizeof (RelationKey );
167
168
ctl .entrysize = sizeof (PartRelationInfo );
168
169
169
170
/* Already exists, recreate */
170
171
if (relations != NULL )
171
172
hash_destroy (relations );
172
173
173
- relations = ShmemInitHash ("Partitioning relation info" , 1024 , & ctl , HASH_ELEM );
174
+ relations = ShmemInitHash ("Partitioning relation info" , 1024 , & ctl , HASH_ELEM | HASH_BLOBS );
174
175
}
175
176
176
177
/*
@@ -191,8 +192,7 @@ load_check_constraints(Oid parent_oid)
191
192
bool nulls [1 ] = {false};
192
193
vals [0 ] = Int32GetDatum (parent_oid );
193
194
194
- prel = (PartRelationInfo * )
195
- hash_search (relations , (const void * ) & parent_oid , HASH_FIND , & found );
195
+ prel = get_pathman_relation_info (parent_oid , NULL );
196
196
197
197
/* Skip if already loaded */
198
198
if (prel -> children .length > 0 )
@@ -219,8 +219,12 @@ load_check_constraints(Oid parent_oid)
219
219
220
220
if (prel -> parttype == PT_RANGE )
221
221
{
222
+ RelationKey key ;
223
+ key .dbid = MyDatabaseId ;
224
+ key .relid = parent_oid ;
225
+
222
226
rangerel = (RangeRelation * )
223
- hash_search (range_restrictions , (void * ) & parent_oid , HASH_ENTER , & found );
227
+ hash_search (range_restrictions , (void * ) & key , HASH_ENTER , & found );
224
228
225
229
alloc_dsm_array (& rangerel -> ranges , sizeof (RangeEntry ), proc );
226
230
ranges = (RangeEntry * ) dsm_array_get_pointer (& rangerel -> ranges );
@@ -297,9 +301,13 @@ load_check_constraints(Oid parent_oid)
297
301
{
298
302
if (ranges [i ].max > ranges [i + 1 ].min )
299
303
{
304
+ RelationKey key ;
305
+ key .dbid = MyDatabaseId ;
306
+ key .relid = parent_oid ;
307
+
300
308
elog (WARNING , "Partitions %u and %u overlap. Disabling pathman for relation %u..." ,
301
309
ranges [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 );
303
311
}
304
312
}
305
313
}
@@ -433,7 +441,7 @@ create_range_restrictions_hashtable()
433
441
HASHCTL ctl ;
434
442
435
443
memset (& ctl , 0 , sizeof (ctl ));
436
- ctl .keysize = sizeof (int );
444
+ ctl .keysize = sizeof (RelationKey );
437
445
ctl .entrysize = sizeof (RangeRelation );
438
446
range_restrictions = ShmemInitHash ("pg_pathman range restrictions" ,
439
447
1024 , & ctl , HASH_ELEM | HASH_BLOBS );
@@ -447,9 +455,12 @@ remove_relation_info(Oid relid)
447
455
{
448
456
PartRelationInfo * prel ;
449
457
RangeRelation * rangerel ;
458
+ RelationKey key ;
459
+
460
+ key .dbid = MyDatabaseId ;
461
+ key .relid = relid ;
450
462
451
- prel = (PartRelationInfo * )
452
- hash_search (relations , (const void * ) & relid , HASH_FIND , 0 );
463
+ prel = get_pathman_relation_info (relid , NULL );
453
464
454
465
/* If there is nothing to remove then just return */
455
466
if (!prel )
@@ -462,11 +473,10 @@ remove_relation_info(Oid relid)
462
473
free_dsm_array (& prel -> children );
463
474
break ;
464
475
case PT_RANGE :
465
- rangerel = (RangeRelation * )
466
- hash_search (range_restrictions , (const void * ) & relid , HASH_FIND , 0 );
476
+ rangerel = get_pathman_range_relation (relid , NULL );
467
477
free_dsm_array (& rangerel -> ranges );
468
478
free_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 );
470
480
break ;
471
481
}
472
482
prel -> children_count = 0 ;
0 commit comments