Skip to content

Commit a7caca9

Browse files
committed
pathman: bugfixes
1 parent 8a1e76c commit a7caca9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

contrib/pathman/pathman.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PG_MODULE_MAGIC;
1919

2020
#define ALL NIL
21+
#define MAX_PARTITIONS 2048
2122

2223
/*
2324
* Partitioning type
@@ -39,8 +40,9 @@ typedef enum PartType
3940
typedef struct PartRelationInfo
4041
{
4142
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];
4446
int children_count;
4547
PartType parttype;
4648
Index attnum;
@@ -169,7 +171,9 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
169171
{
170172
ereport(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

175179
if (length(children) > 0)
@@ -195,6 +199,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
195199
new_rte_array[i] = root->simple_rte_array[i];
196200
}
197201

202+
root->simple_rel_array_size += len;
198203
root->simple_rel_array = new_rel_array;
199204
root->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
{
210215
childOID = (Oid) lfirst_int(lc);
211216
append_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()
585590
prinfo->attnum = DatumGetInt32(SPI_getbinval(tuple, tupdesc, 2, &isnull));
586591
prinfo->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 */
650655
prinfo = (PartRelationInfo*)
651656
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;
654660
}
655661
}
656662

@@ -710,12 +716,14 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
710716
hash_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
{
715722
key.parent_oid = relid;
716723
key.hash = i;
717724
hash_search(hash_restrictions, (const void *)&key, HASH_REMOVE, 0);
718725
}
726+
prel->children_count = 0;
719727
hash_search(relations, (const void *) &relid, HASH_REMOVE, 0);
720728

721729
LWLockRelease(AddinShmemInitLock);

0 commit comments

Comments
 (0)