1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Fix assorted bugs related to identity column in partitioned tables

When changing the data type of a column of a partitioned table, craft
the ALTER SEQUENCE command only once.  Partitions do not have identity
sequences of their own and thus do not need a ALTER SEQUENCE command
for each partition.

Fix getIdentitySequence() to fetch the identity sequence associated
with the top-level partitioned table when a Relation of a partition is
passed to it.  While doing so, translate the attribute number of the
partition into the attribute number of the partitioned table.

Author: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Dmitry Dolgov <9erthalion6@gmail.com>
Discussion: https://www.postgresql.org/message-id/3b8a9dc1-bbc7-0ef5-6863-c432afac7d59@gmail.com
This commit is contained in:
Peter Eisentraut
2024-05-07 22:42:32 +02:00
parent 832c4f657f
commit 509199587d
7 changed files with 100 additions and 47 deletions

View File

@ -24,7 +24,6 @@
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/dependency.h"
#include "catalog/partition.h"
#include "commands/trigger.h"
#include "executor/executor.h"
#include "foreign/fdwapi.h"
@ -1233,24 +1232,8 @@ build_column_default(Relation rel, int attrno)
if (att_tup->attidentity)
{
NextValueExpr *nve = makeNode(NextValueExpr);
Oid reloid;
/*
* The identity sequence is associated with the topmost partitioned
* table.
*/
if (rel->rd_rel->relispartition)
{
List *ancestors =
get_partition_ancestors(RelationGetRelid(rel));
reloid = llast_oid(ancestors);
list_free(ancestors);
}
else
reloid = RelationGetRelid(rel);
nve->seqid = getIdentitySequence(reloid, attrno, false);
nve->seqid = getIdentitySequence(rel, attrno, false);
nve->typeId = att_tup->atttypid;
return (Node *) nve;