mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
Make CREATE OR REPLACE VIEW internally more consistent
The way that columns are added to a view is by calling AlterTableInternal with special subtype AT_AddColumnToView; but that subtype is changed to AT_AddColumnRecurse by ATPrepAddColumn. This has no visible effect in the current code, since views cannot have inheritance children (thus the recursion step is a no-op) and adding a column to a view is executed identically to doing it to a table; but it does make a difference for future event trigger code keeping track of commands, because the current situation leads to confusing the case with a normal ALTER TABLE ADD COLUMN. Fix the problem by passing a flag to ATPrepAddColumn to prevent it from changing the command subtype. The event trigger code can then properly ignore the subcommand. (We could remove the call to ATPrepAddColumn, since views are never typed, and there is never a need for recursion, which are the two conditions that are checked by ATPrepAddColumn; but it seems more future-proof to keep the call in place.)
This commit is contained in:
parent
f65e827058
commit
fbef4342a8
@ -325,7 +325,7 @@ static void ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cm
|
||||
static List *find_typed_table_dependencies(Oid typeOid, const char *typeName,
|
||||
DropBehavior behavior);
|
||||
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
|
||||
AlterTableCmd *cmd, LOCKMODE lockmode);
|
||||
bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode);
|
||||
static void ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
|
||||
ColumnDef *colDef, bool isOid,
|
||||
bool recurse, bool recursing, LOCKMODE lockmode);
|
||||
@ -3085,14 +3085,16 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
||||
case AT_AddColumn: /* ADD COLUMN */
|
||||
ATSimplePermissions(rel,
|
||||
ATT_TABLE | ATT_COMPOSITE_TYPE | ATT_FOREIGN_TABLE);
|
||||
ATPrepAddColumn(wqueue, rel, recurse, recursing, cmd, lockmode);
|
||||
ATPrepAddColumn(wqueue, rel, recurse, recursing, false, cmd,
|
||||
lockmode);
|
||||
/* Recursion occurs during execution phase */
|
||||
pass = AT_PASS_ADD_COL;
|
||||
break;
|
||||
case AT_AddColumnToView: /* add column via CREATE OR REPLACE
|
||||
* VIEW */
|
||||
ATSimplePermissions(rel, ATT_VIEW);
|
||||
ATPrepAddColumn(wqueue, rel, recurse, recursing, cmd, lockmode);
|
||||
ATPrepAddColumn(wqueue, rel, recurse, recursing, true, cmd,
|
||||
lockmode);
|
||||
/* Recursion occurs during execution phase */
|
||||
pass = AT_PASS_ADD_COL;
|
||||
break;
|
||||
@ -4576,7 +4578,7 @@ check_of_type(HeapTuple typetuple)
|
||||
*/
|
||||
static void
|
||||
ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
|
||||
AlterTableCmd *cmd, LOCKMODE lockmode)
|
||||
bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode)
|
||||
{
|
||||
if (rel->rd_rel->reloftype && !recursing)
|
||||
ereport(ERROR,
|
||||
@ -4586,7 +4588,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
|
||||
if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
|
||||
ATTypedTableRecursion(wqueue, rel, cmd, lockmode);
|
||||
|
||||
if (recurse)
|
||||
if (recurse && !is_view)
|
||||
cmd->subtype = AT_AddColumnRecurse;
|
||||
}
|
||||
|
||||
@ -5026,7 +5028,7 @@ ATPrepAddOids(List **wqueue, Relation rel, bool recurse, AlterTableCmd *cmd, LOC
|
||||
cdef->location = -1;
|
||||
cmd->def = (Node *) cdef;
|
||||
}
|
||||
ATPrepAddColumn(wqueue, rel, recurse, false, cmd, lockmode);
|
||||
ATPrepAddColumn(wqueue, rel, recurse, false, false, cmd, lockmode);
|
||||
|
||||
if (recurse)
|
||||
cmd->subtype = AT_AddOidsRecurse;
|
||||
|
Loading…
Reference in New Issue
Block a user