Add distributed checks

Control whether the command run on distributed table
pull/1288/head
velioglu 2017-03-20 15:54:28 +03:00
parent e8aa52f90e
commit 821dead6ca
2 changed files with 19 additions and 29 deletions

View File

@ -1378,16 +1378,16 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
{ {
List *commandList = alterTableStatement->cmds; List *commandList = alterTableStatement->cmds;
ListCell *commandCell = NULL; ListCell *commandCell = NULL;
Oid leftRelationId = InvalidOid; Oid relationId = InvalidOid;
bool isDistributedRelation = false; bool isDistributedRelation = false;
LOCKMODE lockmode = 0; LOCKMODE lockmode = 0;
/* error out if table is not distributed */ /* error out if table is not distributed */
lockmode = AlterTableGetLockLevel(alterTableStatement->cmds); lockmode = AlterTableGetLockLevel(alterTableStatement->cmds);
leftRelationId = AlterTableLookupRelation(alterTableStatement, lockmode); relationId = AlterTableLookupRelation(alterTableStatement, lockmode);
isDistributedRelation = IsDistributedTable(leftRelationId); isDistributedRelation = IsDistributedTable(relationId);
if(!isDistributedRelation) if (!isDistributedRelation)
{ {
return; return;
} }
@ -1444,8 +1444,6 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
HeapTuple tuple = NULL; HeapTuple tuple = NULL;
char *alterColumnName = command->name; char *alterColumnName = command->name;
LOCKMODE lockmode = AlterTableGetLockLevel(alterTableStatement->cmds);
Oid relationId = AlterTableLookupRelation(alterTableStatement, lockmode);
if (!OidIsValid(relationId)) if (!OidIsValid(relationId))
{ {
continue; continue;
@ -1461,7 +1459,7 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
/* reference tables do not have partition column, so allow them */ /* reference tables do not have partition column, so allow them */
if (partitionColumn != NULL && if (partitionColumn != NULL &&
targetAttr->attnum == partitionColumn->varattno) targetAttr->attnum == partitionColumn->varattno)
{ { /* TODO : CHANGE IT ! */
ereport(ERROR, (errmsg("cannot execute ALTER TABLE command " ereport(ERROR, (errmsg("cannot execute ALTER TABLE command "
"involving partition column"))); "involving partition column")));
} }
@ -1474,28 +1472,14 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
case AT_AddConstraint: case AT_AddConstraint:
{ {
Constraint *constraint = (Constraint *) command->def;
Relation relation = NULL; Relation relation = NULL;
char distributionMethod; char distributionMethod;
Var *distributionColumn = NULL; Var *distributionColumn = NULL;
uint32 colocationId = 0; uint32 colocationId = 0;
LOCKMODE lockmode = 0; /* we only allow constraints if they are only subcommand */
Oid leftRelationId = InvalidOid;
lockmode = AlterTableGetLockLevel(alterTableStatement->cmds);
leftRelationId = AlterTableLookupRelation(alterTableStatement, lockmode);
relation = relation_open(leftRelationId, ExclusiveLock);
distributionMethod = PartitionMethod(leftRelationId);
distributionColumn = PartitionKey(leftRelationId);
colocationId = TableColocationId(leftRelationId);
Constraint *constraint = (Constraint *) command->def;
/* 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),
@ -1518,8 +1502,14 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
"supported."))); "supported.")));
} }
distributionMethod = PartitionMethod(relationId);
distributionColumn = PartitionKey(relationId);
colocationId = TableColocationId(relationId);
relation = relation_open(relationId, ExclusiveLock);
ErrorIfNotSupportedConstraint(relation, distributionMethod, ErrorIfNotSupportedConstraint(relation, distributionMethod,
distributionColumn, colocationId); distributionColumn, colocationId);
relation_close(relation, NoLock);
break; break;
} }
@ -1535,8 +1525,8 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("alter table command is currently unsupported"), errmsg("alter table command is currently unsupported"),
errdetail("Only ADD|DROP COLUMN, SET|DROP NOT NULL," errdetail("Only ADD|DROP COLUMN, SET|DROP NOT NULL,"
" SET|DROP DEFAULT, ADD|DROP CONSTRAINT FOREIGN" " SET|DROP DEFAULT, ADD|DROP CONSTRAINT "
" KEY and TYPE subcommands are supported."))); "subcommands are supported.")));
} }
} }
} }

View File

@ -9,8 +9,8 @@
#define SRC_INCLUDE_DISTRIBUTED_CREATE_DISTRIBUTED_TABLE_H_ #define SRC_INCLUDE_DISTRIBUTED_CREATE_DISTRIBUTED_TABLE_H_
extern void ErrorIfNotSupportedConstraint(Relation relation, extern void ErrorIfNotSupportedConstraint(Relation relation,
char distributionMethod, char distributionMethod,
Var *distributionColumn, Var *distributionColumn,
uint32 colocationId); uint32 colocationId);
#endif /* SRC_INCLUDE_DISTRIBUTED_CREATE_DISTRIBUTED_TABLE_H_ */ #endif /* SRC_INCLUDE_DISTRIBUTED_CREATE_DISTRIBUTED_TABLE_H_ */