@@ -12996,7 +12996,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1299612996* existConstraint ;
1299712997SysScanDesc scan ;
1299812998ScanKeyData skey ;
12999- HeapTuple tuple ;
1300012999AttrNumber attno ;
1300113000int natts ;
1300213001TupleDesc tupleDesc ;
@@ -13018,7 +13017,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1301813017errmsg ("\"%s\" is already a partition" ,
1301913018RelationGetRelationName (attachRel ))));
1302013019
13021- if (attachRel -> rd_rel -> reloftype )
13020+ if (OidIsValid ( attachRel -> rd_rel -> reloftype ) )
1302213021ereport (ERROR ,
1302313022(errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1302413023errmsg ("cannot attach a typed table as partition" )));
@@ -13119,9 +13118,10 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1311913118if (attribute -> attisdropped )
1312013119continue ;
1312113120
13122- /* Find same column in parent (matching on column name). */
13123- tuple = SearchSysCacheCopyAttName (RelationGetRelid (rel ),attributeName );
13124- if (!HeapTupleIsValid (tuple ))
13121+ /* Try to find the column in parent (matching on column name) */
13122+ if (!SearchSysCacheExists2 (ATTNAME ,
13123+ ObjectIdGetDatum (RelationGetRelid (rel )),
13124+ CStringGetDatum (attributeName )))
1312513125ereport (ERROR ,
1312613126(errcode (ERRCODE_DATATYPE_MISMATCH ),
1312713127errmsg ("table \"%s\" contains column \"%s\" not found in parent \"%s\"" ,
@@ -13167,7 +13167,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1316713167 * There is a case in which we cannot rely on just the result of the
1316813168 * proof.
1316913169 */
13170- tupleDesc = RelationGetDescr (attachRel );
1317113170attachRel_constr = tupleDesc -> constr ;
1317213171existConstraint = NIL ;
1317313172if (attachRel_constr != NULL )