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

XX000: chunk not found when running update with self join #1555

Closed
feikesteenbergen opened this issue Nov 28, 2019 · 0 comments · Fixed by #1609
Closed

XX000: chunk not found when running update with self join #1555

feikesteenbergen opened this issue Nov 28, 2019 · 0 comments · Fixed by #1609
Assignees
Labels
Milestone

Comments

@feikesteenbergen
Copy link
Member

Relevant system information:

  • OS: Ubuntu 18.04
  • PostgreSQL version: 11.6
  • TimescaleDB version: 1.5.1
  • Installation method: apt (PostgreSQL), source (TimescaleDB)

Describe the bug
When issuing an UPDATE against a compressed hypertable that includes a self-join, the error:

ERROR:  XX000: chunk not found
LOCATION:  chunk_scan_find, chunk.c:1585

is raised. This even occurs when not actually executing the query, but only planning the query.

To Reproduce

CREATE TABLE bugtable (
    inserted timestamptz not null default now(),
    value double precision
);

SELECT create_hypertable(
    'bugtable',
    'inserted',
    chunk_time_interval => interval '1 minute'
);

-- Some dummy data
INSERT INTO
    bugtable
SELECT
    now() - random() * interval '10 minutes'
FROM
    generate_series(1,100);

ALTER TABLE bugtable SET (
  timescaledb.compress
);

SELECT add_compress_chunks_policy(
    'bugtable',
    INTERVAL '1' MINUTE
);

-- ERROR:  XX000: chunk not found
-- LOCATION:  chunk_scan_find, chunk.c:1585
--
-- This problem already occurs when running `EXPLAIN (ANALYZE OFF)` on the query
UPDATE
    bugtable
SET
    value = NULL
WHERE
    inserted = (
        SELECT
            max(inserted)
          FROM 
            bugtable
          WHERE
            inserted > now() - interval '10 seconds'
    )
    AND inserted > now() - interval '10 seconds';

-- Different type of query, but same result

-- ERROR:  XX000: chunk not found
-- LOCATION:  chunk_scan_find, chunk.c:1585
WITH my_cte(max) AS (
    SELECT
        max(inserted)
    FROM
        bugtable
    WHERE
        inserted > now() - interval '10 seconds'
)
UPDATE
    bugtable
SET
    value = NULL
FROM
    my_cte
WHERE
    inserted = max;

-- However, when splitting up the queries and using an intermediate variable, the query runs fine
DO $$
DECLARE
    max timestamptz;
    count bigint;
BEGIN
    SELECT
        max(inserted)
    INTO
        max
    FROM
        bugtable
    WHERE
        inserted < now() - interval '10 minutes';

    UPDATE
        bugtable
    SET
        value = NULL
    WHERE
        inserted = MAX
        AND inserted < now() - interval '10 minutes';

    GET DIAGNOSTICS count = ROW_COUNT;

    RAISE NOTICE 'Updated % rows', count;
END;
$$;

Expected behavior
An update of 0 or 1 rows

Actual behavior
ERROR: XX000: chunk not found

Source of the report
This bug was reported here https://timescaledb.slack.com/archives/C63MYDZ35/p1574933617190200

@bboule bboule added the bug label Dec 3, 2019
@cevian cevian added this to the 1.6.0 milestone Dec 19, 2019
cevian added a commit that referenced this issue Jan 3, 2020
Fix bug with transparent decompression getting the
hypertable parent table. This can happen with self-referencing
updates.

Fixes #1555
cevian added a commit that referenced this issue Jan 3, 2020
Fix bug with transparent decompression getting the
hypertable parent table. This can happen with self-referencing
updates.

Fixes #1555
cevian added a commit that referenced this issue Jan 7, 2020
Fix bug with transparent decompression getting the
hypertable parent table. This can happen with self-referencing
updates.

Fixes #1555
cevian added a commit that referenced this issue Jan 7, 2020
Fix bug with transparent decompression getting the
hypertable parent table. This can happen with self-referencing
updates.

Fixes #1555
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.

3 participants