Change alter check position

Alter table checks are implemented after master command
pull/1288/head
velioglu 2017-03-20 11:53:44 +03:00
parent 8f7e69fd0d
commit e8aa52f90e
1 changed files with 34 additions and 25 deletions

View File

@ -379,7 +379,6 @@ multi_ProcessUtility(Node *parsetree,
ErrorIfUnsupportedAlterTableStmt(alterTableStatement); ErrorIfUnsupportedAlterTableStmt(alterTableStatement);
} }
if (commandMustRunAsOwner) if (commandMustRunAsOwner)
{ {
SetUserIdAndSecContext(savedUserId, savedSecurityContext); SetUserIdAndSecContext(savedUserId, savedSecurityContext);
@ -1379,6 +1378,19 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
{ {
List *commandList = alterTableStatement->cmds; List *commandList = alterTableStatement->cmds;
ListCell *commandCell = NULL; ListCell *commandCell = NULL;
Oid leftRelationId = InvalidOid;
bool isDistributedRelation = false;
LOCKMODE lockmode = 0;
/* error out if table is not distributed */
lockmode = AlterTableGetLockLevel(alterTableStatement->cmds);
leftRelationId = AlterTableLookupRelation(alterTableStatement, lockmode);
isDistributedRelation = IsDistributedTable(leftRelationId);
if(!isDistributedRelation)
{
return;
}
/* error out if any of the subcommands are unsupported */ /* error out if any of the subcommands are unsupported */
foreach(commandCell, commandList) foreach(commandCell, commandList)
@ -1482,19 +1494,17 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
Constraint *constraint = (Constraint *) command->def; Constraint *constraint = (Constraint *) command->def;
/* extra checks for alter table */
if (constraint->contype == CONSTR_FOREIGN)
{
/* we only allow foreign constraints if they are only subcommand */ /* we only allow foreign constraints if they are only subcommand */
if (commandList->length > 1) if (commandList->length > 1)
{ {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create foreign key constraint"), errmsg("cannot create constraint"),
errdetail("Citus cannot execute ADD CONSTRAINT " errdetail("Citus cannot execute ADD CONSTRAINT "
"FOREIGN KEY command together with other " "command together with other subcommands."),
"subcommands."),
errhint("You can issue each subcommand separately"))); errhint("You can issue each subcommand separately")));
} }
/* /*
* We will use constraint name in each placement by extending it at * We will use constraint name in each placement by extending it at
* workers. Therefore we require it to be exist. * workers. Therefore we require it to be exist.
@ -1502,11 +1512,10 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
if (constraint->conname == NULL) if (constraint->conname == NULL)
{ {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create foreign key constraint"), errmsg("cannot create constraint"),
errdetail("Creating foreign constraint without a " errdetail("Creating constraint without a name on a "
"name on a distributed table is currently " "distributed table is currently not "
"not supported."))); "supported.")));
}
} }
ErrorIfNotSupportedConstraint(relation, distributionMethod, ErrorIfNotSupportedConstraint(relation, distributionMethod,