Hi. acquire_inherited_sample_rows() currently uses equalTupleDescs() being false as the condition for going to tupconv.c to determine whether tuple conversion is needed. But equalTupleDescs() will always return false if it's passed TupleDesc's of two different tables, which is the most common case here. So I first thought we should just unconditionally go to tupconv.c, but there is still one case where we don't need to, which is the case where the child table is same as the parent table. However, it would be much cheaper to just check if the relation OIDs are different instead of calling equalTupleDescs, which the attached patch teaches it to do.
Thanks, Amit
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 25194e871c..262299eaee 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -1489,8 +1489,7 @@ acquire_inherited_sample_rows(Relation onerel, int elevel, /* We may need to convert from child's rowtype to parent's */ if (childrows > 0 && - !equalTupleDescs(RelationGetDescr(childrel), - RelationGetDescr(onerel))) + RelationGetRelid(childrel) != RelationGetRelid(onerel)) { TupleConversionMap *map; diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index fe4265d4bb..9b1194d15f 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14560,7 +14560,8 @@ CloneRowTriggersToPartition(Relation parent, Relation partition) col = TupleDescAttr(parent->rd_att, trigForm->tgattr.values[i] - 1); - cols = lappend(cols, makeString(NameStr(col->attname))); + cols = lappend(cols, + makeString(pstrdup(NameStr(col->attname)))); } }