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

[Bug]: Compress_chunk_time_interval fails to adhere to unique indexes. #7743

Open
ArosTRM opened this issue Feb 19, 2025 · 0 comments
Open
Labels

Comments

@ArosTRM
Copy link

ArosTRM commented Feb 19, 2025

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Data ingestion

What happened?

We have started to use compress_chunk_time_interval with to column partitioning (in addition to time column), and after using it we have seen a new error regarding a constraint we are not aware of. When we try to insert a new row we get error:

Error: new row for relation “_hyper_198_440400_chunk” violates check constraint “constraint_427027”
DETAIL: Failing row contains (26213, 2021-02-26 07:00:00+00, 0.000, 2024-09-17 12:45:34.327421+00, 2025-02-18 13:34:18.674494+00, 2024-09-17 12:45:34.327421+00).

It seems that it sometimes allows use to insert duplicates into compressed tables.
Unique index has always been there so it does not make sense how it could have happened.
We are unable to decompress the chunk as it does not adhere to unique index constraints.

TimescaleDB version affected

2.7.0

PostgreSQL version used

16

What operating system did you use?

Stackgres

What installation method did you use?

Not applicable

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

How can we reproduce the bug?

Our insert:
INSERT INTO test (columns) VALUES (values) ON CONFLICT DO NOTHING; 

Our setup: 
CREATE TABLE test (
    idINTEGER NOT NULL,
    d TIMESTAMPTZ NOT NULL,
    v DECIMAL(15, 3) NOT NULL,
    issue_datetime_utc TIMESTAMPTZ NULL,
    extract_datetime_utc TIMESTAMPTZ NOT NULL,
    computed_issue_datetime TIMESTAMPTZ GENERATED ALWAYS AS 
        (COALESCE(issue_datetime_utc, extract_datetime_utc)) STORED
);

SELECT create_hypertable('test', by_range('d', interval '185 days'));

SELECT add_dimension('test', by_hash('id', 512));

CREATE UNIQUE INDEX actuals_curve_id_d_computed_issue_datetime_key
ON archive.actuals (curve_id, d DESC, computed_issue_datetime DESC);

ALTER TABLE test
SET (
    timescaledb.compress,
    timescaledb.compress_segmentby = 'id',
    timescaledb.compress_orderby = 'd, computed_issue_datetime DESC',
    -- Factor of original chunk size
    timescaledb.compress_chunk_time_interval = '740 days'
);
@ArosTRM ArosTRM added the bug label Feb 19, 2025
@ArosTRM ArosTRM changed the title [Bug]: <Title> Compress_chunk_time_interval weird behavior over chunk interval [Bug]: Compress_chunk_time_interval weird behavior over chunk interval Feb 19, 2025
@ArosTRM ArosTRM changed the title [Bug]: Compress_chunk_time_interval weird behavior over chunk interval [Bug]: Compress_chunk_time_interval fails to adhere to unique indexes. Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant