From: | Anand Surelia <anand(at)bytekinc(dot)com> |
---|---|
To: | "pgsql-general(at)postgreSQL(dot)org" <pgsql-general(at)postgreSQL(dot)org>, pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Bug in contrib/spi/refint.c |
Date: | 1998-10-02 21:57:23 |
Message-ID: | 36154C43.122C2BFE@bytekinc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
There is a bug in check_foreign_key of refint.c which is bundled with
the standard distribution. It occurs when a trigger calling this
function recursively fires another trigger which calls the same
function. The calling check_foreign_key loses its plan informantion and
when it tries to use it the backend closes its channel. You can check it
with the sql script I am attaching below.
The solution to this is to do a find_plan again before executing it at
line 483 of refint.c.
Therefore two more lines should be added before line 483:
sprintf(ident, "%s$%u", trigger->tgname, rel->rd_id);
plan = find_plan(ident, &FPlans, &nFPlans);
before line 483 which is:
ret = SPI_execp(plan->splan[r], kvals, NULL, tcount);
Here is the script to check it:
create table a (
a int4 primary key,
b int4,
c int4,
d int4
);
create table b (
a int4 primary key,
b int4,-- foreign key references a
c int4,
d int4
);
create table ab (
a int4 primary key,
b int4,
c int4,
d int4
);
create table bc (
a int4 primary key,
b int4,
c int4,
d int4
);
create function check_primary_key()
returns opaque
as '/home/bye2data/postgresql-6.3.2/contrib/spi/refint.so'
language 'c';
create function check_foreign_key()
returns opaque
as '/home/bye2data/postgresql-6.3.2/contrib/spi/refint.so'
language 'c';
create trigger t1 before delete or update
on a for each row execute procedure
check_foreign_key(1,'cascade','a','b','b');
create trigger t2 before insert or update
on b for each row execute procedure
check_primary_key('b','a','a');
create trigger t3 before delete or update
on ab for each row execute procedure
check_foreign_key(2,'cascade','a','a','a','bc','a');
create trigger t4 before insert or update
on a for each row execute procedure
check_primary_key('a','ab','a');
create trigger t5 before insert or update
on bc for each row execute procedure
check_primary_key('a','ab','a');
insert into ab values(1,1,1,1);
insert into bc values (1,1,1,1);
insert into a values (1,1,1,1);
delete from ab where a=1;
Sorry for the confusing names of tables and attributes.
- Anand.
From | Date | Subject | |
---|---|---|---|
Next Message | Taral | 1998-10-02 22:04:24 | RE: [HACKERS] RE: [GENERAL] Long update query ? (also Re: [GENERAL] CNF vs. DNF) |
Previous Message | Bruce Momjian | 1998-10-02 21:57:15 | Re: [HACKERS] RE: [GENERAL] Long update query ? (also Re: [GENERAL] CNF vs. DNF) |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 1998-10-02 21:58:00 | Open 6.4 items |
Previous Message | Bruce Momjian | 1998-10-02 21:57:15 | Re: [HACKERS] RE: [GENERAL] Long update query ? (also Re: [GENERAL] CNF vs. DNF) |