18
18
PG_MODULE_MAGIC ;
19
19
20
20
#define ALL NIL
21
+ #define MAX_PARTITIONS 2048
21
22
22
23
/*
23
24
* Partitioning type
@@ -39,8 +40,9 @@ typedef enum PartType
39
40
typedef struct PartRelationInfo
40
41
{
41
42
Oid oid ;
42
- List * children ;
43
- // Bitmapset *children;
43
+ // List *children;
44
+ /* TODO: is there any better solution to store children in shared memory? */
45
+ Oid children [MAX_PARTITIONS ];
44
46
int children_count ;
45
47
PartType parttype ;
46
48
Index attnum ;
@@ -169,7 +171,9 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
169
171
{
170
172
ereport (LOG , (errmsg ("Restrictions empty. Copy children from partrel" )));
171
173
// children = get_children_oids(partrel);
172
- children = list_copy (partrel -> children );
174
+ // children = list_copy(partrel->children);
175
+ for (i = 0 ;i < partrel -> children_count ;i ++ )
176
+ children = lappend_int (children ,partrel -> children [i ]);
173
177
}
174
178
175
179
if (length (children )> 0 )
@@ -195,6 +199,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195
199
new_rte_array [i ]= root -> simple_rte_array [i ];
196
200
}
197
201
202
+ root -> simple_rel_array_size += len ;
198
203
root -> simple_rel_array = new_rel_array ;
199
204
root -> simple_rte_array = new_rte_array ;
200
205
/* TODO: free old arrays */
@@ -209,7 +214,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
209
214
{
210
215
childOID = (Oid )lfirst_int (lc );
211
216
append_child_relation (root ,rel ,rti ,rte ,childOID );
212
- root -> simple_rel_array_size += 1 ;
217
+ // root->simple_rel_array_size += 1;
213
218
}
214
219
215
220
/* TODO: clear old path list */
@@ -585,7 +590,7 @@ load_part_relations_hashtable()
585
590
prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
586
591
prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
587
592
/* children will be filled in later */
588
- prinfo -> children = NIL ;
593
+ // prinfo->children = NIL;
589
594
}
590
595
}
591
596
@@ -649,8 +654,9 @@ load_hash_restrictions_hashtable()
649
654
/* appending children to PartRelationInfo */
650
655
prinfo = (PartRelationInfo * )
651
656
hash_search (relations , (const void * )& key .parent_oid ,HASH_ENTER ,& found );
652
- prinfo -> children = lappend_int (prinfo -> children ,child_oid );
653
- prinfo -> children_count ++ ;
657
+ // prinfo->children = lappend_int(prinfo->children, child_oid);
658
+ // prinfo->children_count++;
659
+ prinfo -> children [prinfo -> children_count ++ ]= child_oid ;
654
660
}
655
661
}
656
662
@@ -710,12 +716,14 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
710
716
hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
711
717
712
718
/* remove children relations from hash_restrictions */
713
- for (i = 0 ;i < length (prel -> children );i ++ )
719
+ // for (i=0; i<length(prel->children); i++)
720
+ for (i = 0 ;i < prel -> children_count ;i ++ )
714
721
{
715
722
key .parent_oid = relid ;
716
723
key .hash = i ;
717
724
hash_search (hash_restrictions , (const void * )& key ,HASH_REMOVE ,0 );
718
725
}
726
+ prel -> children_count = 0 ;
719
727
hash_search (relations , (const void * )& relid ,HASH_REMOVE ,0 );
720
728
721
729
LWLockRelease (AddinShmemInitLock );