Re: Index created in BEFORE trigger not updated during INSERT

From: Andres Freund <andres(at)anarazel(dot)de>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Index created in BEFORE trigger not updated during INSERT
Date: 2017-05-24 13:51:32
Message-ID: 20170524135132.v4ol2ldsxhqu5val@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2017-05-24 08:26:24 -0400, Robert Haas wrote:
> On Mon, May 22, 2017 at 7:05 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> wrote:
> > Not that it is a useful use case, but I believe that this is
> > a bug that causes index corruption:
> >
> > CREATE TABLE mytable(
> > id integer PRIMARY KEY,
> > id2 integer NOT NULL
> > );
> >
> > CREATE FUNCTION makeindex() RETURNS trigger
> > LANGUAGE plpgsql AS
> > $$BEGIN
> > CREATE INDEX ON mytable(id2);
> > RETURN NEW;
> > END;$$;
>
> I'm willing to bet that nobody ever thought about that case very hard.
> It seems like we should either make it work or prohibit it, but I
> can't actually see quite how to do either off-hand.

Hm, strategically sprinkled CheckTableNotInUse() might do the trick?
I've neither tried nor thought this through fully, but I can't think of
a case where pre-existing relcache references to tables are ok...

- Andres

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nick Dro 2017-05-24 14:00:20 Error log for psql (uploading backup) in PostgreSQL 9.3.17
Previous Message Michael Paquier 2017-05-24 13:29:11 Re: retry shm attach for windows (WAS: Re: OK, so culicidae is *still* broken)