Skip to content

[Bug]: INSERT INTO ... ON CONFLICT DO NOTHING on compressed chunks exits prematurely when encountering a conflict #7672

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

Closed
bjornuppeke opened this issue Feb 7, 2025 · 0 comments · Fixed by #7673
Labels

Comments

@bjornuppeke
Copy link

What type of bug is this?

Incorrect result

What subsystems and features are affected?

Compression

What happened?

When inserting rows from a temporary table into a hypertable with compressed chunks, with INSERT INTO ... ON CONFLICT DO NOTHING, the transaction exits as soon as a conflict is encountered.

I expect the insert to continue with the next row.

TimescaleDB version affected

2.17.2

PostgreSQL version used

16

What operating system did you use?

docker.io/timescale/timescaledb-ha:pg16-ts2.17 on Mac OS ARM

What installation method did you use?

Docker

What platform did you run on?

Other

Relevant log output and stack trace

How can we reproduce the bug?

create database test;

\c test

CREATE TABLE main (
    id UUID NOT NULL,
    ts TIMESTAMPTZ NOT NULL,
    v FLOAT,
    PRIMARY KEY (id, ts)
);

SELECT create_hypertable('main', by_range('ts'));

ALTER TABLE main SET (timescaledb.compress, timescaledb.compress_orderby = 'ts DESC', timescaledb.compress_segmentby = 'id');

SELECT add_compression_policy('main', compress_after => INTERVAL '60d');

INSERT INTO main VALUES('BFE8F140-AF50-4FD9-BA16-43018AB2EE8A', '2023-01-01T14:00:00', '20');

CALL run_job(1000);

CREATE TABLE temp (LIKE main INCLUDING INDEXES);

DO $$
DECLARE
  start_ts TIMESTAMPTZ := '2023-01-01T00:00:00+0';
  end_ts TIMESTAMPTZ := start_ts + INTERVAL '1 month';
  current_ts TIMESTAMPTZ := start_ts; -- Changed variable name to current_ts
  random_value FLOAT;
BEGIN
  WHILE current_ts < end_ts LOOP
    random_value := random() * 100;

    INSERT INTO temp(id, ts, v)
    VALUES('BFE8F140-AF50-4FD9-BA16-43018AB2EE8A', current_ts, random_value);

    current_ts := current_ts + INTERVAL '1 hour';
  END LOOP;
END $$;

INSERT INTO main (SELECT * FROM temp) ON CONFLICT DO NOTHING;
>> INSERT 0 14
@bjornuppeke bjornuppeke added the bug label Feb 7, 2025
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Feb 7, 2025
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 timescale#7672
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Feb 7, 2025
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 timescale#7672
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Feb 7, 2025
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 timescale#7672
svenklemm added a commit that referenced this issue Feb 10, 2025
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
github-actions bot pushed a commit that referenced this issue Feb 10, 2025
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

(cherry picked from commit 41b141f)
svenklemm added a commit that referenced this issue Feb 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant