diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 83dc151..cc9009d 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -53,16 +53,16 @@ * Information about bounds of a partitioned relation * * A list partition datum that is known to be NULL is never put into the - * datums array, instead it is tracked using has_null and null_index fields. + * datums array. Instead, it is tracked using has_null and null_index fields. * - * In case of range partitioning, ndatums is far less than 2 * nparts, because - * a partition's upper bound and the next partition's lower bound are same - * in most common cases, and we only store one of them. + * In the case of range partitioning, ndatums will typically be far less than + * 2 * nparts, because a partition's upper bound and the next partition's lower + * bound are the same in most common cases, and we only store one of them. * - * In case of list partitioning, the indexes array stores one entry for every - * datum, which is the index of the partition that accepts a given datum. - * Wheareas, in case of range partitioning, it stores one entry per distinct - * range datum, which is the index of the partition of which a given datum + * In the case of list partitioning, the indexes array stores one entry for + * every datum, which is the index of the partition that accepts a given datum. + * In case of range partitioning, it stores one entry per distinct range + * datum, which is the index of the partition for which a given datum * is an upper bound. */ @@ -135,16 +135,19 @@ typedef struct PartitionDispatchData int *indexes; } PartitionDispatchData; -static int32 qsort_partition_list_value_cmp(const void *a, const void *b, void *arg); -static int32 qsort_partition_rbound_cmp(const void *a, const void *b, void *arg); +static int32 qsort_partition_list_value_cmp(const void *a, const void *b, + void *arg); +static int32 qsort_partition_rbound_cmp(const void *a, const void *b, + void *arg); static List *get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec); static List *get_qual_for_range(PartitionKey key, PartitionBoundSpec *spec); -static Oid get_partition_operator(PartitionKey key, int col, StrategyNumber strategy, - bool *need_relabel); +static Oid get_partition_operator(PartitionKey key, int col, + StrategyNumber strategy, bool *need_relabel); static List *generate_partition_qual(Relation rel, bool recurse); -static PartitionRangeBound *make_one_range_bound(PartitionKey key, int index, List *datums, bool lower); +static PartitionRangeBound *make_one_range_bound(PartitionKey key, int index, + List *datums, bool lower); static int32 partition_rbound_cmp(PartitionKey key, Datum *datums1, RangeDatumContent *content1, bool lower1, PartitionRangeBound *b2); @@ -152,9 +155,11 @@ static int32 partition_rbound_datum_cmp(PartitionKey key, Datum *rb_datums, RangeDatumContent *rb_content, Datum *tuple_datums); -static int32 partition_bound_cmp(PartitionKey key, PartitionBoundInfo boundinfo, +static int32 partition_bound_cmp(PartitionKey key, + PartitionBoundInfo boundinfo, int offset, void *probe, bool probe_is_bound); -static int partition_bound_bsearch(PartitionKey key, PartitionBoundInfo boundinfo, +static int partition_bound_bsearch(PartitionKey key, + PartitionBoundInfo boundinfo, void *probe, bool probe_is_bound, bool *is_equal); /* Support get_partition_for_tuple() */ @@ -636,8 +641,8 @@ partition_bounds_equal(PartitionKey key, { int32 cmpval; - cmpval = DatumGetInt32(FunctionCall2Coll(&key->partsupfunc[0], - key->partcollation[0], + cmpval = DatumGetInt32(FunctionCall2Coll(&key->partsupfunc[j], + key->partcollation[j], b1->datums[i][j], b2->datums[i][j])); if (cmpval != 0) @@ -976,7 +981,7 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode, PartitionDesc partdesc = RelationGetPartitionDesc(partrel); /* - * If this partition is a partitined table, add its children to to the + * If this partition is a partitioned table, add its children to the * end of the list, so that they are processed as well. */ if (partdesc) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index abfb46b..c77b216 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1990,9 +1990,9 @@ MergeAttributes(List *schema, List *supers, char relpersistence, pfree(newattno); /* - * Close the parent rel, but keep our ShareUpdateExclusiveLock on it - * until xact commit. That will prevent someone else from deleting or - * ALTERing the parent before the child is committed. + * Close the parent rel, but keep our lock on it until xact commit. + * That will prevent someone else from deleting or ALTERing the parent + * before the child is committed. */ heap_close(relation, NoLock); } diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index c958092..2da7ae3 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1192,7 +1192,7 @@ equalPartitionDescs(PartitionKey key, PartitionDesc partdesc1, /* * Now compare partition bound collections. The logic to iterate over - * the collections is local to partition.c. + * the collections is private to partition.c. */ if (partdesc1->boundinfo != NULL) { @@ -2604,7 +2604,9 @@ RelationClearRelation(Relation relation, bool rebuild) SWAPFIELD(Oid, rd_toastoid); /* pgstat_info must be preserved */ SWAPFIELD(struct PgStat_TableStatus *, pgstat_info); - + /* partition key must be preserved */ + SWAPFIELD(PartitionKey, rd_partkey); + SWAPFIELD(MemoryContext, rd_partkeycxt); /* preserve old partdesc if no logical change */ if (keep_partdesc) {