|
22 | 22 | * |
23 | 23 | * |
24 | 24 | * 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 $ |
26 | 26 | * |
27 | 27 | *------------------------------------------------------------------------- |
28 | 28 | */ |
@@ -973,31 +973,42 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation, |
973 | 973 | * Otherwise we have to search for the matching column by name. |
974 | 974 | * There's no guarantee it'll have the same column position, because |
975 | 975 | * 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. |
976 | 981 | */ |
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 |
978 | 988 | { |
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\"", |
987 | 998 | 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; |
996 | 999 | } |
997 | 1000 |
|
998<
9359
/td> | | - 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", |
1000 | 1004 | 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)); |
1001 | 1012 | } |
1002 | 1013 |
|
1003 | 1014 | *col_mappings = numbers; |
|
0 commit comments