Skip to content

Commit 67a5f8f

Browse files
committed
Department of marginal improvements: teach tupconvert.c to avoid doing a
physical conversion when there are dropped columns in the same places in the input and output tupdescs. This avoids possible performance loss from the recent patch to improve dropped-column handling, in some cases where the old code would have worked.
1 parent 26a90c6 commit 67a5f8f

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/backend/access/common/tupconvert.c

+33-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/access/common/tupconvert.c,v 1.1 2009/08/06 20:44:31 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/access/common/tupconvert.c,v 1.2 2009/08/17 20:34:31 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -146,11 +146,22 @@ convert_tuples_by_position(TupleDesc indesc,
146146
{
147147
for (i = 0; i < n; i++)
148148
{
149-
if (attrMap[i] != (i+1))
150-
{
151-
same = false;
152-
break;
153-
}
149+
if (attrMap[i] == (i+1))
150+
continue;
151+
152+
/*
153+
* If it's a dropped column and the corresponding input
154+
* column is also dropped, we needn't convert. However,
155+
* attlen and attalign must agree.
156+
*/
157+
if (attrMap[i] == 0 &&
158+
indesc->attrs[i]->attisdropped &&
159+
indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
160+
indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
161+
continue;
162+
163+
same = false;
164+
break;
154165
}
155166
}
156167
else
@@ -255,11 +266,22 @@ convert_tuples_by_name(TupleDesc indesc,
255266
same = true;
256267
for (i = 0; i < n; i++)
257268
{
258-
if (attrMap[i] != (i+1))
259-
{
260-
same = false;
261-
break;
262-
}
269+
if (attrMap[i] == (i+1))
270+
continue;
271+
272+
/*
273+
* If it's a dropped column and the corresponding input
274+
* column is also dropped, we needn't convert. However,
275+
* attlen and attalign must agree.
276+
*/
277+
if (attrMap[i] == 0 &&
278+
indesc->attrs[i]->attisdropped &&
279+
indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
280+
indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
281+
continue;
282+
283+
same = false;
284+
break;
263285
}
264286
}
265287
else

0 commit comments

Comments
 (0)