Patch for Bug in RI

Started by Jeroen van Vianenover 25 years ago3 messages
#1Jeroen van Vianen
jeroen.van.vianen@satama.com
1 attachment(s)

Hi,

Following my bug report yesterday about a bug in RI, I'll first show a
reproducible example:

create table t1 ( a int4 primary key, b varchar(5) );
create table t2 ( b varchar(5) primary key );
alter table t1 add constraint fk_t1__b foreign key (b) references t2 (b);
insert into t2 values ( 'abc' );
insert into t2 values ( 'def' );
insert into t1 values ( 1, 'abc' );
-- This statement fails, which is correct
insert into t1 values ( 2, 'xyz' );
insert into t1 values ( 3, 'def' );

-- Now, do the rename table
alter table t2 rename to t3;
-- This statement crashes the backend
insert into t1 values ( 4, 'abc' );

With the attached patch for src/backend/utils/adt/ri_triggers.c, you'll get
the following error message instead:

ERROR: RI constraint fk_t1__b cannot find table t2

Of course, the long-time solution would be to update the pg_triggers table
on alter table X rename to Y. However, I do not feel qualified to implement
this.

I have not executed all different elog()'s that I've added, but I feel
confident they'll work.

Please review my patch,

Jeroen

Attachments:

ri_triggers.patch.gzapplication/x-gzip; name=ri_triggers.patch.gzDownload
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jeroen van Vianen (#1)
Re: Patch for Bug in RI

This oversight (lack of check for heap_open failure) was already fixed
in another way for 7.1 --- heap_open itself always checks now.

regards, tom lane

#3Jeroen van Vianen
jeroen.van.vianen@satama.com
In reply to: Tom Lane (#2)
Re: Patch for Bug in RI

At 10:58 22-9-00 -0400, Tom Lane wrote:

This oversight (lack of check for heap_open failure) was already fixed
in another way for 7.1 --- heap_open itself always checks now.

Cool, I'll wait eagerly for 7.1 ;-)

Jeroen