Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort additional INSERTs when hitting first conflict #7673

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .unreleased/pr_7673
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes: #7673 Don't abort additional INSERTs when hitting first conflict
Thanks: @bjornuppeke for reporting a problem with INSERT INTO ... ON CONFLICT DO NOTHING on compressed chunks
2 changes: 1 addition & 1 deletion src/nodes/hypertable_modify.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ ExecModifyTable(CustomScanState *cs_node, PlanState *pstate)
cds->skip_current_tuple = false;
if (node->ps.instrument)
node->ps.instrument->ntuples2++;
return NULL;
continue;
}

/* No more tuples to process? */
Expand Down
30 changes: 30 additions & 0 deletions tsl/test/expected/compression_conflicts.out
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,33 @@ VALUES
(41, 1609478100000, 'val1')
ON CONFLICT DO NOTHING;
INFO: Using index scan with scan keys: index 1, heap 4, memory 2.
INFO: Using index scan with scan keys: index 1, heap 4, memory 2.
RESET timescaledb.debug_compression_path_info;
-- gh issue #7672
-- check additional INSERTS after hitting ON CONFLICT clause still go through
CREATE TABLE test_i7672(time timestamptz, device text, primary key(time,device));
SELECT create_hypertable('test_i7672', 'time');
create_hypertable
--------------------------
(13,public,test_i7672,t)
(1 row)

ALTER TABLE test_i7672 SET (timescaledb.compress, timescaledb.compress_orderby='time DESC', timescaledb.compress_segmentby='device');
INSERT INTO test_i7672 VALUES ('2025-01-01','d1');
SELECT count(*) FROM (SELECT compress_chunk(show_chunks('test_i7672'))) c;
count
-------
1
(1 row)

INSERT INTO test_i7672 VALUES
('2025-01-01','d1'),
('2025-01-01','d2')
ON CONFLICT DO NOTHING;
SELECT * FROM test_i7672 t ORDER BY t;
time | device
------------------------------+--------
Wed Jan 01 00:00:00 2025 PST | d1
Wed Jan 01 00:00:00 2025 PST | d2
(2 rows)

18 changes: 18 additions & 0 deletions tsl/test/sql/compression_conflicts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,21 @@ VALUES
(41, 1609478100000, 'val1')
ON CONFLICT DO NOTHING;

RESET timescaledb.debug_compression_path_info;

-- gh issue #7672
-- check additional INSERTS after hitting ON CONFLICT clause still go through
CREATE TABLE test_i7672(time timestamptz, device text, primary key(time,device));
SELECT create_hypertable('test_i7672', 'time');
ALTER TABLE test_i7672 SET (timescaledb.compress, timescaledb.compress_orderby='time DESC', timescaledb.compress_segmentby='device');
INSERT INTO test_i7672 VALUES ('2025-01-01','d1');

SELECT count(*) FROM (SELECT compress_chunk(show_chunks('test_i7672'))) c;

INSERT INTO test_i7672 VALUES
('2025-01-01','d1'),
('2025-01-01','d2')
ON CONFLICT DO NOTHING;

SELECT * FROM test_i7672 t ORDER BY t;

Loading