find-composite-type-dependencies-refactor.patch
text/x-diff
Filename: find-composite-type-dependencies-refactor.patch
Type: text/x-diff
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 34 | 29 |
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 6a17399..83f8be0 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -3378,23 +3378,6 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
}
/*
- * If we change column data types or add/remove OIDs, the operation has to
- * be propagated to tables that use this table's rowtype as a column type.
- * newrel will also be non-NULL in the case where we're adding a column
- * with a default. We choose to forbid that case as well, since composite
- * types might eventually support defaults.
- *
- * (Eventually we'll probably need to check for composite type
- * dependencies even when we're just scanning the table without a rewrite,
- * but at the moment a composite type does not enforce any constraints,
- * so it's not necessary/appropriate to enforce them just during ALTER.)
- */
- if (newrel)
- find_composite_type_dependencies(oldrel->rd_rel->reltype,
- oldrel->rd_rel->relkind,
- RelationGetRelationName(oldrel));
-
- /*
* Generate the constraint and default execution states
*/
@@ -4055,7 +4038,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
Oid typeOid;
int32 typmod;
Form_pg_type tform;
- Expr *defval;
+ Expr *defval = NULL;
attrdesc = heap_open(AttributeRelationId, RowExclusiveLock);
@@ -4304,6 +4287,20 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
tab->new_changeoids = true;
/*
+ * If we're adding an OID column, the operation has to be propagated to
+ * tables that use this table's rowtype as a column type. But we don't
+ * currently have the infrastructure for that, so just throw an error.
+ * We also forbid the case where we're adding a column with a default, since
+ * composite types might eventually support defaults, and ALTER TABLE ..
+ * ADD COLUMN .. DEFAULT would be expected to initialize the newly added
+ * column to the default in each instantiation of the rowtype.
+ */
+ if (isOid || defval)
+ find_composite_type_dependencies(rel->rd_rel->reltype,
+ rel->rd_rel->relkind,
+ RelationGetRelationName(rel));
+
+ /*
* Add needed dependency entries for the new column.
*/
add_column_datatype_dependency(myrelid, newattnum, attribute.atttypid);
@@ -4975,6 +4972,16 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
/* Tell Phase 3 to physically remove the OID column */
tab->new_changeoids = true;
+
+ /*
+ * The OID removal operation needs to be propagated to tables that use
+ * this table's rowtype as a column type. But we don't currently have
+ * the infrastructure for that, so just throw an error if it would be
+ * required.
+ */
+ find_composite_type_dependencies(rel->rd_rel->reltype,
+ rel->rd_rel->relkind,
+ RelationGetRelationName(rel));
}
}
@@ -6442,17 +6449,15 @@ ATPrepAlterColumnType(List **wqueue,
errmsg("ALTER TYPE USING is not supported on foreign tables")));
}
- if (tab->relkind == RELKIND_COMPOSITE_TYPE
- || tab->relkind == RELKIND_FOREIGN_TABLE)
- {
- /*
- * For composite types, do this check now. Tables will check
- * it later when the table is being rewritten.
- */
- find_composite_type_dependencies(rel->rd_rel->reltype,
- rel->rd_rel->relkind,
- RelationGetRelationName(rel));
- }
+ /*
+ * If we change column data types, the operation has to be propagated to
+ * tables that use this table's rowtype as a column type. But we don't
+ * currently have the infrastructure for that, so just throw an error
+ * if it would be required.
+ */
+ find_composite_type_dependencies(rel->rd_rel->reltype,
+ rel->rd_rel->relkind,
+ RelationGetRelationName(rel));
ReleaseSysCache(tuple);