From 5ac4d27ebf34a29334dc5822e179559098c534f4 Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 26 Dec 2016 17:44:14 +0900 Subject: [PATCH 3/3] Avoid tuple coversion in common partitioning cases Currently, the tuple conversion is performed after a tuple is routed, even if the attributes of a target leaf partition map one-to-one with those of the root table, which is wasteful. Avoid that by making convert_tuples_by_name() return a NULL map for such cases. Reported by: n/a Patch by: Amit Langote Reports: n/a --- src/backend/access/common/tupconvert.c | 9 +++++---- src/backend/catalog/partition.c | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c index b17ceafa6e..7c5427e987 100644 --- a/src/backend/access/common/tupconvert.c +++ b/src/backend/access/common/tupconvert.c @@ -214,12 +214,13 @@ convert_tuples_by_name(TupleDesc indesc, attrMap = convert_tuples_by_name_map(indesc, outdesc, msg); /* - * Check to see if the map is one-to-one and the tuple types are the same. - * (We check the latter because if they're not, we want to do conversion - * to inject the right OID into the tuple datum.) + * Check to see if the map is one-to-one, in which case we need not do + * tuple conversion. That's not enough though if one of either source or + * destination (tuples) contains OIDs; we'd need conversion in that case + * to inject the right OID into the tuple datum. */ if (indesc->natts == outdesc->natts && - indesc->tdtypeid == outdesc->tdtypeid) + indesc->tdhasoid != outdesc->tdhasoid) { same = true; for (i = 0; i < n; i++) diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 9b2a71d0d5..f1d888a336 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -1682,12 +1682,11 @@ get_partition_for_tuple(PartitionDispatch *pd, return -1; } - if (myslot != NULL) + if (myslot != NULL && map != NULL) { HeapTuple tuple = ExecFetchSlotTuple(slot); ExecClearTuple(myslot); - Assert(map != NULL); tuple = do_convert_tuple(tuple, map); ExecStoreTuple(tuple, myslot, InvalidBuffer, true); slot = myslot; -- 2.11.0