Code review for ATExecAttachPartition.

Amit Langote.  Most of this reported by Álvaro Herrera.
This commit is contained in:
Robert Haas 2016-12-22 12:39:19 -05:00
parent c444868389
commit 3ee8067284
1 changed files with 5 additions and 6 deletions

View File

@ -12996,7 +12996,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
*existConstraint; *existConstraint;
SysScanDesc scan; SysScanDesc scan;
ScanKeyData skey; ScanKeyData skey;
HeapTuple tuple;
AttrNumber attno; AttrNumber attno;
int natts; int natts;
TupleDesc tupleDesc; TupleDesc tupleDesc;
@ -13018,7 +13017,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
errmsg("\"%s\" is already a partition", errmsg("\"%s\" is already a partition",
RelationGetRelationName(attachRel)))); RelationGetRelationName(attachRel))));
if (attachRel->rd_rel->reloftype) if (OidIsValid(attachRel->rd_rel->reloftype))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE), (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot attach a typed table as partition"))); errmsg("cannot attach a typed table as partition")));
@ -13119,9 +13118,10 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
if (attribute->attisdropped) if (attribute->attisdropped)
continue; continue;
/* Find same column in parent (matching on column name). */ /* Try to find the column in parent (matching on column name) */
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), attributeName); if (!SearchSysCacheExists2(ATTNAME,
if (!HeapTupleIsValid(tuple)) ObjectIdGetDatum(RelationGetRelid(rel)),
CStringGetDatum(attributeName)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH), (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("table \"%s\" contains column \"%s\" not found in parent \"%s\"", errmsg("table \"%s\" contains column \"%s\" not found in parent \"%s\"",
@ -13167,7 +13167,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
* There is a case in which we cannot rely on just the result of the * There is a case in which we cannot rely on just the result of the
* proof. * proof.
*/ */
tupleDesc = RelationGetDescr(attachRel);
attachRel_constr = tupleDesc->constr; attachRel_constr = tupleDesc->constr;
existConstraint = NIL; existConstraint = NIL;
if (attachRel_constr != NULL) if (attachRel_constr != NULL)