Skip to content

Commit 9546a9e

Browse files
committed
Don't abort additional INSERTs when hitting first conflict
When an INSERT with ON CONFLICT DO NOTHING hits the first conflicts it would abort additional INSERTS following the INSERT triggering the DO NOTHING clause leading to missed INSERTs. Fixes #7672
1 parent caa6568 commit 9546a9e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/nodes/hypertable_modify.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ ExecModifyTable(CustomScanState *cs_node, PlanState *pstate)
728728
cds->skip_current_tuple = false;
729729
if (node->ps.instrument)
730730
node->ps.instrument->ntuples2++;
731-
return NULL;
731+
continue;
732732
}
733733

734734
/* No more tuples to process? */

tsl/test/expected/compression_conflicts.out

+30
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,33 @@ VALUES
748748
(41, 1609478100000, 'val1')
749749
ON CONFLICT DO NOTHING;
750750
INFO: Using index scan with scan keys: index 1, heap 4, memory 2.
751+
INFO: Using index scan with scan keys: index 1, heap 4, memory 2.
752+
RESET timescaledb.debug_compression_path_info;
753+
-- gh issue #7672
754+
-- check additional INSERTS after hitting ON CONFLICT clause still go through
755+
CREATE TABLE test_i7672(time timestamptz, device text, primary key(time,device));
756+
SELECT create_hypertable('test_i7672', 'time');
757+
create_hypertable
758+
--------------------------
759+
(13,public,test_i7672,t)
760+
(1 row)
761+
762+
ALTER TABLE test_i7672 SET (timescaledb.compress, timescaledb.compress_orderby='time DESC', timescaledb.compress_segmentby='device');
763+
INSERT INTO test_i7672 VALUES ('2025-01-01','d1');
764+
SELECT count(*) FROM (SELECT compress_chunk(show_chunks('test_i7672'))) c;
765+
count
766+
-------
767+
1
768+
(1 row)
769+
770+
INSERT INTO test_i7672 VALUES
771+
('2025-01-01','d1'),
772+
('2025-01-01','d2')
773+
ON CONFLICT DO NOTHING;
774+
SELECT * FROM test_i7672 t ORDER BY t;
775+
time | device
776+
------------------------------+--------
777+
Wed Jan 01 00:00:00 2025 PST | d1
778+
Wed Jan 01 00:00:00 2025 PST | d2
779+
(2 rows)
780+

tsl/test/sql/compression_conflicts.sql

+18
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,21 @@ VALUES
518518
(41, 1609478100000, 'val1')
519519
ON CONFLICT DO NOTHING;
520520

521+
RESET timescaledb.debug_compression_path_info;
522+
523+
-- gh issue #7672
524+
-- check additional INSERTS after hitting ON CONFLICT clause still go through
525+
CREATE TABLE test_i7672(time timestamptz, device text, primary key(time,device));
526+
SELECT create_hypertable('test_i7672', 'time');
527+
ALTER TABLE test_i7672 SET (timescaledb.compress, timescaledb.compress_orderby='time DESC', timescaledb.compress_segmentby='device');
528+
INSERT INTO test_i7672 VALUES ('2025-01-01','d1');
529+
530+
SELECT count(*) FROM (SELECT compress_chunk(show_chunks('test_i7672'))) c;
531+
532+
INSERT INTO test_i7672 VALUES
533+
('2025-01-01','d1'),
534+
('2025-01-01','d2')
535+
ON CONFLICT DO NOTHING;
536+
537+
SELECT * FROM test_i7672 t ORDER BY t;
538+

0 commit comments

Comments
 (0)