#6509·paradedb

Skip filter clause evaluation on segments whose bounds fully enclose the filter range

Author: stuhoodCreated Sep 26, 2026Updated Sep 29, 2026
Labelsbugpriority-highuser-request

Bug Report

What happens?

When an index is partitioned with partition_by, SegmentPruner::can_match evaluates whether individual segments can contribute matching documents based on per-segment min and max bounding ranges recorded in segment metadata.

When a segment's bounds are completely contained within a query filter range (for example, the segment's created_at range falls entirely within created_at >= '2024-01-01'), all documents within that segment are guaranteed to satisfy the predicate. However, during execution, the segment reader still evaluates the full filter query against all documents in that segment.

In pg_search/src/query/segment_pruning.rs, matches_all is currently only used to evaluate negation clauses (must_not) for segment candidate selection: https://github.com/paradedb/paradedb/blob/739a11c59d9d08625a619fb9f351300949e1a0b5/pg_search/src/query/segment_pruning.rs#L263-L265

And in pg_search/src/index/reader/index.rs, candidate segments execute the compiled query in full: https://github.com/paradedb/paradedb/blob/739a11c59d9d08625a619fb9f351300949e1a0b5/pg_search/src/index/reader/index.rs#L855-L861

There is currently no mechanism during search execution to skip evaluating filter clauses on candidate segments that are proven to be fully enclosed by the predicate bounds. This optimization is needed for the partitioning behavior described in https://github.com/paradedb/paradedb/pull/6288.

To Reproduce

  1. Create a partitioned table and index with multiple segments:
sql
CREATE TABLE items (id BIGSERIAL PRIMARY KEY, tenant_id INT, created_at TIMESTAMP, description TEXT);
INSERT INTO items (tenant_id, created_at, description)
SELECT g, '2024-01-01'::timestamp + (g || ' days')::interval, 'item ' || g
FROM generate_series(1, 1000) g;

CREATE INDEX items_idx ON items USING paradedb (id, tenant_id, created_at, description)
WITH (partition_by = 'created_at', target_segment_count = 8);
  1. Run a query whose filter completely encloses the bounds of one or more segments:
sql
EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM items
WHERE created_at >= '2024-01-01' AND description ||| 'item'
LIMIT 10;
  1. Candidate segments whose bounds fall entirely within created_at >= '2024-01-01' still evaluate the created_at predicate on each document rather than skipping evaluation of the fully satisfied clause.

Expected Behavior

Segments whose metadata bounds prove that 100% of their documents satisfy a filter predicate should evaluate only the remaining query clauses (e.g. description ||| 'item'), skipping evaluation of the enclosed filter clause.

Environment

  • OS: macOS / Linux
  • ParadeDB Version: 0.25.x / 0.26.0-alpha
  • Are you using ParadeDB Docker, Helm, or the extension(s) standalone? ParadeDB pg_search Extension

Identity Disclosure

  • Full Name: Stu Hood
  • Affiliation: ParadeDB

Confirmation

  • Did you include all relevant data sets for reproducing the issue? N/A - The reproduction does not require a data set
  • Did you include the code required to reproduce the issue? Yes, I have
  • Did you include all relevant configurations to reproduce the issue? Yes, I have