[HACKERS] Index created in BEFORE trigger not updated during INSERT - Mailing list pgsql-hackers

From Albe Laurenz
Subject [HACKERS] Index created in BEFORE trigger not updated during INSERT
Date
Msg-id A737B7A37273E048B164557ADEF4A58B53A4DC9A@ntex2010i.host.magwien.gv.at
Whole thread Raw
Responses Re: [HACKERS] Index created in BEFORE trigger not updated during INSERT
List pgsql-hackers
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;$$;

CREATE TRIGGER makeindex BEFORE INSERT ON mytable FOR EACH ROW  EXECUTE PROCEDURE makeindex();

INSERT INTO mytable VALUES (1, 42);

SELECT * FROM mytable;
┌────┬─────┐
│ id │ id2 │
├────┼─────┤
│  1 │  42 │
└────┴─────┘
(1 row)

But 42 is not present in the index:

SET enable_seqscan = off;

SELECT * FROM mytable WHERE id2 = 42;
┌────┬─────┐
│ id │ id2 │
├────┼─────┤
└────┴─────┘
(0 rows)

pgsql-hackers by date:

Previous
From: Kuntal Ghosh
Date:
Subject: Re: [HACKERS] "create publication..all tables" ignore 'partition notsupported' error
Next
From: Kuntal Ghosh
Date:
Subject: Re: [HACKERS] pg_dump ignoring information_schema tables which usedin Create Publication.