Huh, this code is broken as well. We have to ignore partitions that don't
have any subpartitions. Patch is attached below (v2).
--
Dmitry Ivanov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 219d380..6555c7c 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -950,7 +950,8 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
*parted_rels;
ListCell *lc;
int i,
- k;
+ k,
+ partitioned_children_so_far = 0;
/*
* Lock partitions and make a list of the partitioned ones to prepare
@@ -1001,7 +1002,7 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
PartitionKey partkey = RelationGetPartitionKey(partrel);
PartitionDesc partdesc = RelationGetPartitionDesc(partrel);
int j,
- m;
+ my_partitioned_children;
pd[i] = (PartitionDispatch) palloc(sizeof(PartitionDispatchData));
pd[i]->reldesc = partrel;
@@ -1010,7 +1011,7 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
pd[i]->partdesc = partdesc;
pd[i]->indexes = (int *) palloc(partdesc->nparts * sizeof(int));
- m = 0;
+ my_partitioned_children = 0;
for (j = 0; j < partdesc->nparts; j++)
{
Oid partrelid = partdesc->oids[j];
@@ -1026,11 +1027,21 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
* We can assign indexes this way because of the way
* parted_rels has been generated.
*/
- pd[i]->indexes[j] = -(i + 1 + m);
- m++;
+ pd[i]->indexes[j] = -(1 +
+ my_partitioned_children +
+ partitioned_children_so_far);
+
+ my_partitioned_children++;
}
}
i++;
+
+ /*
+ * Children of this parent should be placed after all
+ * partitioned children of all previous parents, so we
+ * have to take this into account.
+ */
+ partitioned_children_so_far += my_partitioned_children;
}
return pd;
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers