On 06/25/2018 08:00 AM, David Rowley wrote:
I'd have expected Test 6 to do about 480-500tps. Adding debug to check
why it's not revealed that the search is doing what's expected. I'm
unsure why it has not improved more.

I think I found one possible reason for this slowness. Your patch behaves as expected when there is a dropped output column, but does one extra comparison when there is a dropped input column. This backwards conversion is called from ExecInitRoutingInfo. To fix this, I'd just keep a persistent inner loop counter (see the attached patch).

Still, fixing this doesn't improve the performance. According to perf report, updatepd.sql spends 25% of time in strcmp, and updatep.sql about 0.5%, but they are comparing the same column names, even with the same alignment and relative offsets. I'm completely puzzled by this.

As a side thought, we wouldn't have to go through this if we had a hash table that is easy to use, or perhaps string interning in catcache.

--
Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c
index 2d0d2f4..573ddd82 100644
--- a/src/backend/access/common/tupconvert.c
+++ b/src/backend/access/common/tupconvert.c
@@ -297,6 +297,7 @@ convert_tuples_by_name_map(TupleDesc indesc,
 	AttrNumber *attrMap;
 	int			n;
 	int			i;
+	int nextInput = -1;
 
 	n = outdesc->natts;
 	attrMap = (AttrNumber *) palloc0(n * sizeof(AttrNumber));
@@ -315,7 +316,13 @@ convert_tuples_by_name_map(TupleDesc indesc,
 		atttypmod = outatt->atttypmod;
 		for (j = 0; j < indesc->natts; j++)
 		{
-			Form_pg_attribute inatt = TupleDescAttr(indesc, j);
+			Form_pg_attribute inatt;
+
+			nextInput++;
+			if (nextInput >= indesc->natts)
+				nextInput = 0;
+
+			inatt = TupleDescAttr(indesc, nextInput);
 
 			if (inatt->attisdropped)
 				continue;
@@ -330,7 +337,7 @@ convert_tuples_by_name_map(TupleDesc indesc,
 									   attname,
 									   format_type_be(outdesc->tdtypeid),
 									   format_type_be(indesc->tdtypeid))));
-				attrMap[i] = (AttrNumber) (j + 1);
+				attrMap[i] = (AttrNumber) (nextInput + 1);
 				break;
 			}
 		}

Reply via email to