1818PG_MODULE_MAGIC ;
1919
2020#define ALL NIL
21+ #define MAX_PARTITIONS 2048
2122
2223/*
2324 * Partitioning type
@@ -39,8 +40,9 @@ typedef enum PartType
3940typedef struct PartRelationInfo
4041{
4142Oid 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 ];
4446int children_count ;
4547PartType parttype ;
4648Index attnum ;
@@ -169,7 +171,9 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
169171{
170172ereport (LOG , (errmsg ("Restrictions empty. Copy children from partrel" )));
171173// 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 ]);
173177}
174178
175179if (length (children )> 0 )
@@ -195,6 +199,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195199new_rte_array [i ]= root -> simple_rte_array [i ];
196200}
197201
202+ root -> simple_rel_array_size += len ;
198203root -> simple_rel_array = new_rel_array ;
199204root -> simple_rte_array = new_rte_array ;
200205/* TODO: free old arrays */
@@ -209,7 +214,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
209214{
210215childOID = (Oid )lfirst_int (lc );
211216append_child_relation (root ,rel ,rti ,rte ,childOID );
212- root -> simple_rel_array_size += 1 ;
217+ // root->simple_rel_array_size += 1;
213218}
214219
215220/* TODO: clear old path list */
@@ -585,7 +590,7 @@ load_part_relations_hashtable()
585590prinfo -> attnum = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,2 ,& isnull ));
586591prinfo -> parttype = DatumGetInt32 (SPI_getbinval (tuple ,tupdesc ,3 ,& isnull ));
587592/* children will be filled in later */
588- prinfo -> children = NIL ;
593+ // prinfo->children = NIL;
589594}
590595}
591596
@@ -649,8 +654,9 @@ load_hash_restrictions_hashtable()
649654/* appending children to PartRelationInfo */
650655prinfo = (PartRelationInfo * )
651656hash_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 ;
654660 }
655661 }
656662
@@ -710,12 +716,14 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
710716hash_search (relations , (const void * )& relid ,HASH_FIND ,0 );
711717
712718/* 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 ++ )
714721{
715722key .parent_oid = relid ;
716723key .hash = i ;
717724hash_search (hash_restrictions , (const void * )& key ,HASH_REMOVE ,0 );
718725}
726+ prel -> children_count = 0 ;
719727hash_search (relations , (const void * )& relid ,HASH_REMOVE ,0 );
720728
721729LWLockRelease (AddinShmemInitLock );