diff options
author | Peter Eisentraut | 2024-03-17 11:19:30 +0000 |
---|---|---|
committer | Peter Eisentraut | 2024-03-17 11:30:51 +0000 |
commit | d939cb2fd612acde0304913213cfbdb01994e682 (patch) | |
tree | dacc70fa1b94cc377245ff9f14c7166745e5939f /src/backend/catalog/index.c | |
parent | 012460ee93c304fbc7220e5b55d9d0577fc766ab (diff) |
Generalize handling of nullable pg_attribute columns in DDL
DDL code uses tuple descriptors to pass around pg_attribute values
during table and index creation. But tuple descriptors don't include
the variable-length/nullable columns of pg_attribute, so they have to
be handled separately. Right now, the attoptions field is handled in
a one-off way with a separate argument passed to
InsertPgAttributeTuples(). The other affected fields of pg_attribute
are right now not needed at relation creation time.
The goal of this patch is to generalize this to allow handling
additional variable-length/nullable columns of pg_attribute in a
similar manner. For that, create a new struct
FormExtraData_pg_attribute, which is to be passed around in parallel
to the tuple descriptor and optionally supplies the additional
columns. Right now, this struct only contains one field for
attoptions, so no functionality is actually changed by this.
Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/catalog/index.c')
-rw-r--r-- | src/backend/catalog/index.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index e6140853c05..7e428f3eb79 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -512,6 +512,20 @@ AppendAttributeTuples(Relation indexRelation, const Datum *attopts) Relation pg_attribute; CatalogIndexState indstate; TupleDesc indexTupDesc; + FormExtraData_pg_attribute *attrs_extra = NULL; + + if (attopts) + { + attrs_extra = palloc0_array(FormExtraData_pg_attribute, indexRelation->rd_att->natts); + + for (int i = 0; i < indexRelation->rd_att->natts; i++) + { + if (attopts[i]) + attrs_extra[i].attoptions.value = attopts[i]; + else + attrs_extra[i].attoptions.isnull = true; + } + } /* * open the attribute relation and its indexes @@ -525,7 +539,7 @@ AppendAttributeTuples(Relation indexRelation, const Datum *attopts) */ indexTupDesc = RelationGetDescr(indexRelation); - InsertPgAttributeTuples(pg_attribute, indexTupDesc, InvalidOid, attopts, indstate); + InsertPgAttributeTuples(pg_attribute, indexTupDesc, InvalidOid, attrs_extra, indstate); CatalogCloseIndexes(indstate); |