citus icon indicating copy to clipboard operation
citus copied to clipboard

Columnar ON CONFLICT DO NOTHING fails on tables with PK

Open hanefi opened this issue 1 year ago • 0 comments

ON CONFLICT DO NOTHING fails on tables that have unique constraints or primary keys. Columnar readme file implies that it should work.

CREATE TABLE test_log (
    id int NOT NULL,
    descr text,
    PRIMARY KEY (id))
USING columnar;

INSERT INTO test_log (id, descr)
    VALUES (1, 'teststr')
ON CONFLICT
    DO NOTHING;
ERROR:  XX000: columnar_tuple_insert_speculative not implemented
LOCATION:  columnar_tuple_insert_speculative, columnar_tableam.c:766

The same error happens when we have a unique constraint instead of a primary key.

If there are no primary keys or unique constraints, the query works. However, PostgreSQL does not detect conflicts in that scenario and ON CONFLICT DO NOTHING does not really impact the query in any way.

CREATE TABLE test_log_without_pk (
    id int NOT NULL,
    descr text)
USING columnar;

INSERT INTO test_log_without_pk (id, descr)
    VALUES (1, 'teststr')
ON CONFLICT
    DO NOTHING;

INSERT INTO test_log_without_pk (id, descr)
    VALUES (1, 'teststr')
ON CONFLICT
    DO NOTHING;

SELECT
    *
FROM
    test_log_without_pk;
+----+---------+
| id |  descr  |
+----+---------+
|  1 | teststr |
|  1 | teststr |
+----+---------+
(2 rows)

hanefi avatar Sep 06 '22 11:09 hanefi