Skip to content

Commit 925ca9d

Browse files
committed
Tweak make_inh_translation_lists() to check the common case wherein parent and
child attnums are the same, before it grovels through each and every child column looking for a name match. Saves some time in large inheritance trees, per example from Greg.
1 parent 402bd49 commit 925ca9d

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

src/backend/optimizer/prep/prepunion.c

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.140 2007/03/17 00:11:04 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.141 2007/04/21 05:56:41 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -973,31 +973,42 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation,
973973
* Otherwise we have to search for the matching column by name.
974974
* There's no guarantee it'll have the same column position, because
975975
* of cases like ALTER TABLE ADD COLUMN and multiple inheritance.
976+
* However, in simple cases it will be the same column number, so
977+
* try that before we go groveling through all the columns.
978+
*
979+
* Note: the test for (att = ...) != NULL cannot fail, it's just a
980+
* notational device to include the assignment into the if-clause.
976981
*/
977-
for (new_attno = 0; new_attno < newnatts; new_attno++)
982+
if (old_attno < newnatts &&
983+
(att = new_tupdesc->attrs[old_attno]) != NULL &&
984+
!att->attisdropped && att->attinhcount != 0 &&
985+
strcmp(attname, NameStr(att->attname)) == 0)
986+
new_attno = old_attno;
987+
else
978988
{
979-
att = new_tupdesc->attrs[new_attno];
980-
if (att->attisdropped || att->attinhcount == 0)
981-
continue;
982-
if (strcmp(attname, NameStr(att->attname)) != 0)
983-
continue;
984-
/* Found it, check type */
985-
if (atttypid != att->atttypid || atttypmod != att->atttypmod)
986-
elog(ERROR, "attribute \"%s\" of relation \"%s\" does not match parent's type",
989+
for (new_attno = 0; new_attno < newnatts; new_attno++)
990+
{
991+
att = new_tupdesc->attrs[new_attno];
992+
if (!att->attisdropped && att->attinhcount != 0 &&
993+
strcmp(attname, NameStr(att->attname)) == 0)
994+
break;
995+
}
996+
if (new_attno >= newnatts)
997+
elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"",
987998
attname, RelationGetRelationName(newrelation));
988-
989-
numbers = lappend_int(numbers, new_attno + 1);
990-
vars = lappend(vars, makeVar(newvarno,
991-
(AttrNumber) (new_attno + 1),
992-
atttypid,
993-
atttypmod,
994-
0));
995-
break;
996999
}
9971000

998-
if (new_attno >= newnatts)
999-
elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"",
1001+
/* Found it, check type */
1002+
if (atttypid != att->atttypid || atttypmod != att->atttypmod)
1003+
elog(ERROR, "attribute \"%s\" of relation \"%s\" does not match parent's type",
10001004
attname, RelationGetRelationName(newrelation));
1005+
1006+
numbers = lappend_int(numbers, new_attno + 1);
1007+
vars = lappend(vars, makeVar(newvarno,
1008+
(AttrNumber) (new_attno + 1),
1009+
atttypid,
1010+
atttypmod,
1011+
0));
10011012
}
10021013

10031014
*col_mappings = numbers;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy