Re: Odd behavior observed - Mailing list pgsql-general

From Tom Lane
Subject Re: Odd behavior observed
Date
Msg-id 14998.1158688720@sss.pgh.pa.us
Whole thread Raw
In response to Re: Odd behavior observed  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I wrote:
> ... I think maybe
> something is applying an UPDATE to the row and losing the new value
> at that point.  Are any of the FKs non-default actions (ON ... SET NULL
> or some such that would try to alter data instead of just erroring)?

I've been able to reproduce a problem that may or may not be Marc's
problem, but it's definitely a bug:

regression=# create table foo(f1 int primary key);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
regression=# create table bar(f1 int references foo on delete set null);
CREATE TABLE
regression=# insert into foo values(1);
INSERT 0 1
regression=# insert into bar values(1);
INSERT 0 1
regression=# delete from foo;
DELETE 1
regression=# select * from bar;
 f1
----

(1 row)

regression=# alter table bar add column f2 int;
ALTER TABLE
regression=# insert into foo values(1);
INSERT 0 1
regression=# insert into bar values(1,2);
INSERT 0 1
regression=# select * from bar;
 f1 | f2
----+----
    |
  1 |  2
(2 rows)

regression=# delete from foo;
DELETE 1
regression=# select * from bar;
 f1 | f2
----+----
    |
    |
(2 rows)

regression=#

f2 should clearly not have gotten set to null there.  I believe the
problem is that we have a stale cached plan for the ON DELETE SET NULL
referential action.  Still another reason why we need a plan
invalidation mechanism :-(

            regards, tom lane

pgsql-general by date:

Previous
From: Marc Evans
Date:
Subject: Re: Odd behavior observed
Next
From: Tom Lane
Date:
Subject: Re: Odd behavior observed