Reverting previous commit, pending investigation
of sporadic seg faults from various build farm members.
This commit is contained in:
parent
b577a57d41
commit
4f14c86d74
@ -46,7 +46,6 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
|
|||||||
ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
|
ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
|
||||||
ADD <replaceable class="PARAMETER">table_constraint</replaceable> [ NOT VALID ]
|
ADD <replaceable class="PARAMETER">table_constraint</replaceable> [ NOT VALID ]
|
||||||
ADD <replaceable class="PARAMETER">table_constraint_using_index</replaceable>
|
ADD <replaceable class="PARAMETER">table_constraint_using_index</replaceable>
|
||||||
ALTER CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
|
|
||||||
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
|
VALIDATE CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable>
|
||||||
DROP CONSTRAINT [ IF EXISTS ] <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
|
DROP CONSTRAINT [ IF EXISTS ] <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
|
||||||
DISABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ]
|
DISABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ]
|
||||||
@ -317,16 +316,6 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><literal>ALTER CONSTRAINT</literal></term>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
This form alters the attributes of a constraint that was previously
|
|
||||||
created. Currently only foreign key constraints may be altered.
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>VALIDATE CONSTRAINT</literal></term>
|
<term><literal>VALIDATE CONSTRAINT</literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -275,8 +275,6 @@ static void AlterIndexNamespaces(Relation classRel, Relation rel,
|
|||||||
static void AlterSeqNamespaces(Relation classRel, Relation rel,
|
static void AlterSeqNamespaces(Relation classRel, Relation rel,
|
||||||
Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved,
|
Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved,
|
||||||
LOCKMODE lockmode);
|
LOCKMODE lockmode);
|
||||||
static void ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
|
|
||||||
bool recurse, bool recursing, LOCKMODE lockmode);
|
|
||||||
static void ATExecValidateConstraint(Relation rel, char *constrName,
|
static void ATExecValidateConstraint(Relation rel, char *constrName,
|
||||||
bool recurse, bool recursing, LOCKMODE lockmode);
|
bool recurse, bool recursing, LOCKMODE lockmode);
|
||||||
static int transformColumnNameList(Oid relId, List *colList,
|
static int transformColumnNameList(Oid relId, List *colList,
|
||||||
@ -2888,7 +2886,6 @@ AlterTableGetLockLevel(List *cmds)
|
|||||||
case AT_SetOptions:
|
case AT_SetOptions:
|
||||||
case AT_ResetOptions:
|
case AT_ResetOptions:
|
||||||
case AT_SetStorage:
|
case AT_SetStorage:
|
||||||
case AT_AlterConstraint:
|
|
||||||
case AT_ValidateConstraint:
|
case AT_ValidateConstraint:
|
||||||
cmd_lockmode = ShareUpdateExclusiveLock;
|
cmd_lockmode = ShareUpdateExclusiveLock;
|
||||||
break;
|
break;
|
||||||
@ -3127,9 +3124,6 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
|||||||
ATPrepAddInherit(rel);
|
ATPrepAddInherit(rel);
|
||||||
pass = AT_PASS_MISC;
|
pass = AT_PASS_MISC;
|
||||||
break;
|
break;
|
||||||
case AT_AlterConstraint: /* ALTER CONSTRAINT */
|
|
||||||
ATSimplePermissions(rel, ATT_TABLE);
|
|
||||||
break;
|
|
||||||
case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
|
case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
|
||||||
ATSimplePermissions(rel, ATT_TABLE);
|
ATSimplePermissions(rel, ATT_TABLE);
|
||||||
/* Recursion occurs during execution phase */
|
/* Recursion occurs during execution phase */
|
||||||
@ -3308,9 +3302,6 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
|
|||||||
case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */
|
case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */
|
||||||
ATExecAddIndexConstraint(tab, rel, (IndexStmt *) cmd->def, lockmode);
|
ATExecAddIndexConstraint(tab, rel, (IndexStmt *) cmd->def, lockmode);
|
||||||
break;
|
break;
|
||||||
case AT_AlterConstraint: /* ALTER CONSTRAINT */
|
|
||||||
ATExecAlterConstraint(rel, cmd, false, false, lockmode);
|
|
||||||
break;
|
|
||||||
case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
|
case AT_ValidateConstraint: /* VALIDATE CONSTRAINT */
|
||||||
ATExecValidateConstraint(rel, cmd->name, false, false, lockmode);
|
ATExecValidateConstraint(rel, cmd->name, false, false, lockmode);
|
||||||
break;
|
break;
|
||||||
@ -6182,135 +6173,6 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
|
|||||||
heap_close(pkrel, NoLock);
|
heap_close(pkrel, NoLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* ALTER TABLE ALTER CONSTRAINT
|
|
||||||
*
|
|
||||||
* Update the attributes of a constraint.
|
|
||||||
*
|
|
||||||
* Currently only works for Foreign Key constraints.
|
|
||||||
* Foreign keys do not inherit, so we purposely ignore the
|
|
||||||
* recursion bit here, but we keep the API the same for when
|
|
||||||
* other constraint types are supported.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd,
|
|
||||||
bool recurse, bool recursing, LOCKMODE lockmode)
|
|
||||||
{
|
|
||||||
Relation conrel;
|
|
||||||
SysScanDesc scan;
|
|
||||||
ScanKeyData key;
|
|
||||||
HeapTuple contuple;
|
|
||||||
Form_pg_constraint currcon = NULL;
|
|
||||||
Constraint *cmdcon = NULL;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
Assert(IsA(cmd->def, Constraint));
|
|
||||||
cmdcon = (Constraint *) cmd->def;
|
|
||||||
|
|
||||||
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Find and check the target constraint
|
|
||||||
*/
|
|
||||||
ScanKeyInit(&key,
|
|
||||||
Anum_pg_constraint_conrelid,
|
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(RelationGetRelid(rel)));
|
|
||||||
scan = systable_beginscan(conrel, ConstraintRelidIndexId,
|
|
||||||
true, SnapshotNow, 1, &key);
|
|
||||||
|
|
||||||
while (HeapTupleIsValid(contuple = systable_getnext(scan)))
|
|
||||||
{
|
|
||||||
currcon = (Form_pg_constraint) GETSTRUCT(contuple);
|
|
||||||
if (strcmp(NameStr(currcon->conname), cmdcon->conname) == 0)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
||||||
errmsg("constraint \"%s\" of relation \"%s\" does not exist",
|
|
||||||
cmdcon->conname, RelationGetRelationName(rel))));
|
|
||||||
|
|
||||||
if (currcon->contype != CONSTRAINT_FOREIGN)
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
|
||||||
errmsg("constraint \"%s\" of relation \"%s\" is not a foreign key constraint",
|
|
||||||
cmdcon->conname, RelationGetRelationName(rel))));
|
|
||||||
|
|
||||||
if (currcon->condeferrable != cmdcon->deferrable ||
|
|
||||||
currcon->condeferred != cmdcon->initdeferred)
|
|
||||||
{
|
|
||||||
HeapTuple copyTuple;
|
|
||||||
HeapTuple tgtuple;
|
|
||||||
Form_pg_constraint copy_con;
|
|
||||||
Form_pg_trigger copy_tg;
|
|
||||||
ScanKeyData tgkey;
|
|
||||||
SysScanDesc tgscan;
|
|
||||||
Relation tgrel;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now update the catalog, while we have the door open.
|
|
||||||
*/
|
|
||||||
copyTuple = heap_copytuple(contuple);
|
|
||||||
copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
|
|
||||||
copy_con->condeferrable = cmdcon->deferrable;
|
|
||||||
copy_con->condeferred = cmdcon->initdeferred;
|
|
||||||
simple_heap_update(conrel, ©Tuple->t_self, copyTuple);
|
|
||||||
CatalogUpdateIndexes(conrel, copyTuple);
|
|
||||||
|
|
||||||
InvokeObjectPostAlterHook(ConstraintRelationId,
|
|
||||||
HeapTupleGetOid(contuple), 0);
|
|
||||||
|
|
||||||
heap_freetuple(copyTuple);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now we need to update the multiple entries in pg_trigger
|
|
||||||
* that implement the constraint.
|
|
||||||
*/
|
|
||||||
tgrel = heap_open(TriggerRelationId, RowExclusiveLock);
|
|
||||||
|
|
||||||
ScanKeyInit(&tgkey,
|
|
||||||
Anum_pg_trigger_tgconstraint,
|
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
|
||||||
ObjectIdGetDatum(HeapTupleGetOid(contuple)));
|
|
||||||
|
|
||||||
tgscan = systable_beginscan(tgrel, TriggerConstraintIndexId, true,
|
|
||||||
SnapshotNow, 1, &tgkey);
|
|
||||||
|
|
||||||
while (HeapTupleIsValid(tgtuple = systable_getnext(tgscan)))
|
|
||||||
{
|
|
||||||
copyTuple = heap_copytuple(tgtuple);
|
|
||||||
copy_tg = (Form_pg_trigger) GETSTRUCT(copyTuple);
|
|
||||||
copy_tg->tgdeferrable = cmdcon->deferrable;
|
|
||||||
copy_tg->tginitdeferred = cmdcon->initdeferred;
|
|
||||||
simple_heap_update(tgrel, ©Tuple->t_self, copyTuple);
|
|
||||||
CatalogUpdateIndexes(tgrel, copyTuple);
|
|
||||||
|
|
||||||
InvokeObjectPostAlterHook(TriggerRelationId,
|
|
||||||
HeapTupleGetOid(tgtuple), 0);
|
|
||||||
|
|
||||||
heap_freetuple(copyTuple);
|
|
||||||
}
|
|
||||||
|
|
||||||
systable_endscan(tgscan);
|
|
||||||
|
|
||||||
heap_close(tgrel, RowExclusiveLock);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Invalidate relcache so that others see the new attributes.
|
|
||||||
*/
|
|
||||||
CacheInvalidateRelcache(rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
systable_endscan(scan);
|
|
||||||
|
|
||||||
heap_close(conrel, RowExclusiveLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ALTER TABLE VALIDATE CONSTRAINT
|
* ALTER TABLE VALIDATE CONSTRAINT
|
||||||
*
|
*
|
||||||
|
@ -1941,21 +1941,6 @@ alter_table_cmd:
|
|||||||
n->def = $2;
|
n->def = $2;
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
/* ALTER TABLE <name> ALTER CONSTRAINT ... */
|
|
||||||
| ALTER CONSTRAINT name ConstraintAttributeSpec
|
|
||||||
{
|
|
||||||
AlterTableCmd *n = makeNode(AlterTableCmd);
|
|
||||||
Constraint *c = makeNode(Constraint);
|
|
||||||
n->subtype = AT_AlterConstraint;
|
|
||||||
n->def = (Node *) c;
|
|
||||||
c->contype = CONSTR_FOREIGN; /* others not supported, yet */
|
|
||||||
c->conname = $3;
|
|
||||||
processCASbits($4, @4, "ALTER CONSTRAINT statement",
|
|
||||||
&c->deferrable,
|
|
||||||
&c->initdeferred,
|
|
||||||
NULL, NULL, yyscanner);
|
|
||||||
$$ = (Node *)n;
|
|
||||||
}
|
|
||||||
/* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
|
/* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
|
||||||
| VALIDATE CONSTRAINT name
|
| VALIDATE CONSTRAINT name
|
||||||
{
|
{
|
||||||
|
@ -1209,7 +1209,6 @@ typedef enum AlterTableType
|
|||||||
AT_AddConstraint, /* add constraint */
|
AT_AddConstraint, /* add constraint */
|
||||||
AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
|
AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
|
||||||
AT_ReAddConstraint, /* internal to commands/tablecmds.c */
|
AT_ReAddConstraint, /* internal to commands/tablecmds.c */
|
||||||
AT_AlterConstraint, /* alter constraint */
|
|
||||||
AT_ValidateConstraint, /* validate constraint */
|
AT_ValidateConstraint, /* validate constraint */
|
||||||
AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
|
AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
|
||||||
AT_ProcessedConstraint, /* pre-processed add constraint (local in
|
AT_ProcessedConstraint, /* pre-processed add constraint (local in
|
||||||
|
@ -1132,15 +1132,6 @@ CREATE TEMP TABLE fktable (
|
|||||||
id int primary key,
|
id int primary key,
|
||||||
fk int references pktable deferrable initially deferred
|
fk int references pktable deferrable initially deferred
|
||||||
);
|
);
|
||||||
-- check ALTER CONSTRAINT
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
|
|
||||||
-- illegal option
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
ERROR: constraint declared INITIALLY DEFERRED must be DEFERRABLE
|
|
||||||
LINE 1: ...e ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY ...
|
|
||||||
^
|
|
||||||
-- reset
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
INSERT INTO pktable VALUES (5, 10);
|
INSERT INTO pktable VALUES (5, 10);
|
||||||
BEGIN;
|
BEGIN;
|
||||||
-- doesn't match PK, but no error yet
|
-- doesn't match PK, but no error yet
|
||||||
@ -1151,16 +1142,6 @@ UPDATE fktable SET id = id + 1;
|
|||||||
COMMIT;
|
COMMIT;
|
||||||
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_fk_fkey"
|
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_fk_fkey"
|
||||||
DETAIL: Key (fk)=(20) is not present in table "pktable".
|
DETAIL: Key (fk)=(20) is not present in table "pktable".
|
||||||
-- change the constraint definition and retest
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY IMMEDIATE;
|
|
||||||
BEGIN;
|
|
||||||
-- doesn't match PK, should throw error now
|
|
||||||
INSERT INTO fktable VALUES (0, 20);
|
|
||||||
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_fk_fkey"
|
|
||||||
DETAIL: Key (fk)=(20) is not present in table "pktable".
|
|
||||||
COMMIT;
|
|
||||||
-- reset
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
-- check same case when insert is in a different subtransaction than update
|
-- check same case when insert is in a different subtransaction than update
|
||||||
BEGIN;
|
BEGIN;
|
||||||
-- doesn't match PK, but no error yet
|
-- doesn't match PK, but no error yet
|
||||||
|
@ -818,13 +818,6 @@ CREATE TEMP TABLE fktable (
|
|||||||
fk int references pktable deferrable initially deferred
|
fk int references pktable deferrable initially deferred
|
||||||
);
|
);
|
||||||
|
|
||||||
-- check ALTER CONSTRAINT
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
|
|
||||||
-- illegal option
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
-- reset
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
|
|
||||||
INSERT INTO pktable VALUES (5, 10);
|
INSERT INTO pktable VALUES (5, 10);
|
||||||
|
|
||||||
BEGIN;
|
BEGIN;
|
||||||
@ -838,19 +831,6 @@ UPDATE fktable SET id = id + 1;
|
|||||||
-- should catch error from initial INSERT
|
-- should catch error from initial INSERT
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
-- change the constraint definition and retest
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY IMMEDIATE;
|
|
||||||
|
|
||||||
BEGIN;
|
|
||||||
|
|
||||||
-- doesn't match PK, should throw error now
|
|
||||||
INSERT INTO fktable VALUES (0, 20);
|
|
||||||
|
|
||||||
COMMIT;
|
|
||||||
|
|
||||||
-- reset
|
|
||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey DEFERRABLE INITIALLY DEFERRED;
|
|
||||||
|
|
||||||
-- check same case when insert is in a different subtransaction than update
|
-- check same case when insert is in a different subtransaction than update
|
||||||
|
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user