Skip to content

Compressed DELETE deletes the rows it shouldn't (data loss)Β #10129

Closed

Description

@akuzm
-- Direct batch delete on compressed hypertable silently deletes rows  
-- when segmentby predicate is <> ANY(NULL::array).
              
CREATE TABLE trade_ticks (  
    ts       timestamptz NOT NULL,
    exchange int,
    price    int
);
SELECT create_hypertable('trade_ticks', 'ts',
                         chunk_time_interval => interval '1 day');  
ALTER TABLE trade_ticks SET ( 
    timescaledb.compress,                           
    timescaledb.compress_segmentby = 'exchange',           
    timescaledb.compress_orderby   = 'ts'              
);
                                                         
INSERT INTO trade_ticks  
SELECT '2024-01-01'::timestamptz + (g * interval '5 minutes'),
       g % 4, g 
FROM generate_series(0, 287) g;
      
SELECT compress_chunk(c) FROM show_chunks('trade_ticks') c;
              
-- Predicate matches zero rows:  
SELECT count(*) AS matching_rows
FROM trade_ticks
WHERE exchange <> ANY (NULL::int[]);
-- matching_rows = 0                              

-- Baseline: optimization off, correct result.        
BEGIN;                                                       
SET LOCAL timescaledb.enable_compressed_direct_batch_delete = off;
DELETE FROM trade_ticks WHERE exchange <> ANY (NULL::int[]);
-- DELETE 0 
SELECT count(*) AS rows_baseline FROM trade_ticks;  
-- rows_baseline = 288
ROLLBACK;          
                          
-- Bug: direct batch delete silently removes rows.
DELETE FROM trade_ticks WHERE exchange <> ANY (NULL::int[]);
-- DELETE 216, expected DELETE 0 
SELECT count(*) AS rows_after FROM trade_ticks;             
-- rows_after = 72, expected 288
SELECT exchange, count(*) FROM trade_ticks GROUP BY exchange ORDER BY exchange;  
-- only exchange=0 survives 

Looks like this is our favorite mechanism: direct batch delete tries to guess which conditions were pushed down to compressed scan instead of using the ground truth, and guesses wrong.

Activity

  1. self-assigned this
    on Jun 26, 2026
  2. modified the milestone: v2.28.2 on Jun 29, 2026
  3. added 9 commits that reference this issue on Jul 13, 2026
    08ec5ea
    a334958
    46e42c5
    4c3c1e8
    82a80e8
    e667732
    2fac7bb
    2235b2b
    5de7c90
  4. added 3 commits that reference this issue on Jul 14, 2026
    3d105f9
    2ea28cb
    1548a8f
  5. added a commit that references this issue on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions