Thread: pgsql: Instead of supposing (wrongly, in the general case) that the
pgsql: Instead of supposing (wrongly, in the general case) that the
From
tgl@svr1.postgresql.org (Tom Lane)
Date:
Log Message: ----------- Instead of supposing (wrongly, in the general case) that the rowtype of an inheritance child table is binary-compatible with the rowtype of its parent, invent an expression node type that does the conversion correctly. Fixes the new bug exhibited by Kris Shannon as well as a lot of old bugs that would only show up when using multiple inheritance or after altering the parent table. Modified Files: -------------- pgsql/src/backend/executor: execQual.c (r1.169 -> r1.170) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/executor/execQual.c.diff?r1=1.169&r2=1.170) pgsql/src/backend/nodes: copyfuncs.c (r1.293 -> r1.294) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/copyfuncs.c.diff?r1=1.293&r2=1.294) equalfuncs.c (r1.232 -> r1.233) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/equalfuncs.c.diff?r1=1.232&r2=1.233) outfuncs.c (r1.243 -> r1.244) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/outfuncs.c.diff?r1=1.243&r2=1.244) readfuncs.c (r1.173 -> r1.174) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/readfuncs.c.diff?r1=1.173&r2=1.174) pgsql/src/backend/optimizer/prep: prepjointree.c (r1.23 -> r1.24) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepjointree.c.diff?r1=1.23&r2=1.24) prepunion.c (r1.117 -> r1.118) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepunion.c.diff?r1=1.117&r2=1.118) pgsql/src/backend/optimizer/util: clauses.c (r1.184 -> r1.185) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/util/clauses.c.diff?r1=1.184&r2=1.185) pgsql/src/backend/parser: parse_coerce.c (r2.124 -> r2.125) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_coerce.c.diff?r1=2.124&r2=2.125) parse_expr.c (r1.176 -> r1.177) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_expr.c.diff?r1=1.176&r2=1.177) pgsql/src/backend/utils/adt: ruleutils.c (r1.185 -> r1.186) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/ruleutils.c.diff?r1=1.185&r2=1.186) pgsql/src/include/nodes: execnodes.h (r1.120 -> r1.121) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/execnodes.h.diff?r1=1.120&r2=1.121) nodes.h (r1.161 -> r1.162) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/nodes.h.diff?r1=1.161&r2=1.162) primnodes.h (r1.104 -> r1.105) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/primnodes.h.diff?r1=1.104&r2=1.105) pgsql/src/pl/plpgsql/src: pl_exec.c (r1.123 -> r1.124) (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpgsql/src/pl_exec.c.diff?r1=1.123&r2=1.124)
Tom Lane wrote: > Instead of supposing (wrongly, in the general case) that the rowtype > of an inheritance child table is binary-compatible with the rowtype of > its parent, invent an expression node type that does the conversion > correctly. Fixes the new bug exhibited by Kris Shannon as well as a > lot of old bugs that would only show up when using multiple inheritance > or after altering the parent table. Attached is a patch adding regression tests for this change. I'll apply it to HEAD later tonight or tomorrow baring any objections. I just used the two test cases posted in the -hackers thread; Tom, if you have any other test cases for this behavior in mind, just let me know. -Neil --- src/test/regress/expected/inherit.out +++ src/test/regress/expected/inherit.out @@ -623,3 +623,31 @@ 32 | one | two | three (1 row) +-- Tests for casting between the rowtypes of parent and child +-- tables. See the pgsql-hackers thread beginning Dec. 4/04 +create table base (i integer); +create table derived () inherits (base); +insert into derived (i) values (0); +select derived::base from derived; + derived +--------- + (0) +(1 row) + +drop table derived; +drop table base; +create table p1(ff1 int); +create table p2(f1 text); +create function p2text(p2) returns text as 'select $1.f1' language sql; +create table c1(f3 int) inherits(p1,p2); +insert into c1 values(123456789, 'hi', 42); +select p2text(c1.*) from c1; + p2text +-------- + hi +(1 row) + +drop function p2text(p2); +drop table c1; +drop table p2; +drop table p1; --- src/test/regress/sql/inherit.sql +++ src/test/regress/sql/inherit.sql @@ -146,7 +146,25 @@ -- Test changing the type of inherited columns insert into d values('test','one','two','three'); +alter table a alter column aa type integer using bit_length(aa); +select * from d; -alter table a alter column aa type integer using bit_length(aa); +-- Tests for casting between the rowtypes of parent and child +-- tables. See the pgsql-hackers thread beginning Dec. 4/04 +create table base (i integer); +create table derived () inherits (base); +insert into derived (i) values (0); +select derived::base from derived; +drop table derived; +drop table base; +create table p1(ff1 int); +create table p2(f1 text); +create function p2text(p2) returns text as 'select $1.f1' language sql; +create table c1(f3 int) inherits(p1,p2); +insert into c1 values(123456789, 'hi', 42); +select p2text(c1.*) from c1; +drop function p2text(p2); +drop table c1; +drop table p2; +drop table p1; -select * from d;
On Sun, 2004-12-12 at 18:11 +1100, Neil Conway wrote: > Attached is a patch adding regression tests for this change. Applied. -Neil