Re: issues with range types, btree_gist and constraints
От | Tomas Vondra |
---|---|
Тема | Re: issues with range types, btree_gist and constraints |
Дата | |
Msg-id | 51102270.6050105@fuzzy.cz обсуждение исходный текст |
Ответ на | issues with range types, btree_gist and constraints (Tomas Vondra <tv@fuzzy.cz>) |
Ответы |
Re: issues with range types, btree_gist and constraints
Re: issues with range types, btree_gist and constraints |
Список | pgsql-hackers |
Hi, I've managed to further simplify the test-case, and I've verified that it's reproducible on current 9.2 and 9.3 branches. This is the necessary table structure: ----------------------------------------------------------------------- CREATE TABLE test ( id TEXT, valid TSRANGE NOT NULL DEFAULT tsrange(NULL, NULL), CONSTRAINT unique_ids EXCLUDEUSING GIST (id WITH =, valid WITH &&) ); CREATE OR REPLACE FUNCTION skip_existing() RETURNS trigger AS $$ DECLARE v_exists BOOLEAN; BEGIN SELECT TRUE INTO v_exists FROM test WHERE id = NEW.id; IF v_exists THEN RETURN NULL; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER skip_existing BEFORE INSERT ON test FOR EACH ROW EXECUTE PROCEDURE skip_existing(); ----------------------------------------------------------------------- I've been unable to reproduce the bug with just a single text column. The trigger simply skips existing records without throwing any error. Now let's insert some data into the table - I'll use the same samples as in the previous test-case (http://www.fuzzy.cz/tmp/samples.tgz). test=# copy test(id) from '/tmp/sample-1.csv'; COPY 20001 test=# copy test(id) from '/tmp/sample-2.csv'; COPY 18590 test=# copy test(id) from '/tmp/sample-1.csv'; COPY 25 test=# copy test(id) from '/tmp/sample-2.csv'; COPY 45 The last two results are really suspicious - it means that some record were inserted "again", so let's verify that: test=# select id, count(*) from test group by id having count(*) > 1; id | count ----------------------------------+-------0aab4791e1e41f62fd8452ae2c854a34 | 20aa08441cd4526b972bb3451d9f8e4ea | 20ab969a3333342837484ec0f81bf1e03 | 20aea0c33c76b1fe5d123b18cec184dc0 | 20af75a99b37be6dde08afaa69de36d29 | 20af80d2c2931756b897b3ca5a0055820| 2... many more ... On 9.3 the number of duplicates is much lower, and it's not stable - on one run I get 6, on the very next one I get 2, then 5 and so on. That leads me to a suspicion that it might be an uninitialized variable or something like that. Tomas
В списке pgsql-hackers по дате отправления: