summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas2016-12-22 17:39:19 +0000
committerRobert Haas2016-12-22 17:40:45 +0000
commit3ee80672847c4100d5f9efdb9ea19cb96506d089 (patch)
treed0ce23be24e058ad12860b6c43af7efa1e71374c /src
parentc4448683893bd37b59003603bc9075d362e81b5a (diff)
Code review for ATExecAttachPartition.
Amit Langote. Most of this reported by Álvaro Herrera.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablecmds.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 115b98313e3..ee79b726f2e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -12996,7 +12996,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
*existConstraint;
SysScanDesc scan;
ScanKeyData skey;
- HeapTuple tuple;
AttrNumber attno;
int natts;
TupleDesc tupleDesc;
@@ -13018,7 +13017,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
errmsg("\"%s\" is already a partition",
RelationGetRelationName(attachRel))));
- if (attachRel->rd_rel->reloftype)
+ if (OidIsValid(attachRel->rd_rel->reloftype))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot attach a typed table as partition")));
@@ -13119,9 +13118,10 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
if (attribute->attisdropped)
continue;
- /* Find same column in parent (matching on column name). */
- tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), attributeName);
- if (!HeapTupleIsValid(tuple))
+ /* Try to find the column in parent (matching on column name) */
+ if (!SearchSysCacheExists2(ATTNAME,
+ ObjectIdGetDatum(RelationGetRelid(rel)),
+ CStringGetDatum(attributeName)))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
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
* proof.
*/
- tupleDesc = RelationGetDescr(attachRel);
attachRel_constr = tupleDesc->constr;
existConstraint = NIL;
if (attachRel_constr != NULL)