Skip to content

Commit 8e14408

Browse files
committed
Make equalTupleDescs() compare attlen/attbyval/attalign rather than
assuming comparison of atttypid is sufficient. In a dropped column atttypid will be 0, and we'd better check the physical-storage data to make sure the tupdescs are physically compatible. I do not believe there is a real risk before 8.0, since before that we only used this routine to compare successive states of the tupdesc for a particular relation. But 8.0's typcache.c might be comparing arbitrary tupdescs so we'd better play it safer.
1 parent 0453a99 commit 8e14408

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/backend/access/common/tupdesc.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.110 2005/03/31 22:46:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.111 2005/04/14 22:34:48 tgl Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -274,23 +274,34 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
274274

275275
/*
276276
* We do not need to check every single field here: we can
277-
* disregard attrelid, attnum (it was used to place the row in the
278-
* attrs array) and everything derived from the column datatype.
279-
* Also, attcacheoff must NOT be checked since it's possibly not
280-
* set in both copies.
277+
* disregard attrelid and attnum (which were used to place the row
278+
* in the attrs array in the first place). It might look like we
279+
* could dispense with checking attlen/attbyval/attalign, since these
280+
* are derived from atttypid; but in the case of dropped columns
281+
* we must check them (since atttypid will be zero for all dropped
282+
* columns) and in general it seems safer to check them always.
283+
*
284+
* attcacheoff must NOT be checked since it's possibly not set
285+
* in both copies.
281286
*/
282287
if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
283288
return false;
284289
if (attr1->atttypid != attr2->atttypid)
285290
return false;
286291
if (attr1->attstattarget != attr2->attstattarget)
287292
return false;
293+
if (attr1->attlen != attr2->attlen)
294+
return false;
288295
if (attr1->attndims != attr2->attndims)
289296
return false;
290297
if (attr1->atttypmod != attr2->atttypmod)
291298
return false;
299+
if (attr1->attbyval != attr2->attbyval)
300+
return false;
292301
if (attr1->attstorage != attr2->attstorage)
293302
return false;
303+
if (attr1->attalign != attr2->attalign)
304+
return false;
294305
if (attr1->attnotnull != attr2->attnotnull)
295306
return false;
296307
if (attr1->atthasdef != attr2->atthasdef)

0 commit comments

Comments
 (0)