Skip to content

Fix timestamp split pruning by rounding metadata bounds outward - #6865

Open
fmassot wants to merge 5 commits into
mainfrom
fmassot/fix-sort-desc-split-pruning
Open

fmassot wants to merge 5 commits into
mainfrom
fmassot/fix-sort-desc-split-pruning

Conversation

@fmassot

@fmassot fmassot commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

For a timestamp-descending top-10 search:

  • After searching one split, the 10th hit is at 1601.758 s. Any newer document should enter the top 10.
  • Another split contains 1601.900 s, but its stored maximum is truncated to 1601.
  • Pruning rounds the 10th hit up to 1602, then skips the split because 1601 < 1602—missing a better hit.

Sorting splits does not prevent this: several splits can have the same truncated maximum.

Fix

As suggested by @PSeitz, store split bounds as floor(min)..=ceil(max). In the example, the upper bound becomes 1602, so the split is searched. Search logic and metadata format/version stay unchanged.

Newly indexed splits only: old metadata is not repaired, and merges inheriting old bounds can retain the bug. Overflow handling at timestamp limits during merges is left for a follow-up.

Tests

Metadata rounding and same-second pruning (descending, ascending, trace IDs), including negative timestamps.

make fmt and git diff --check passed. Indexing/search crate tests: 458 passed, 1 skipped. The previous 1B-document benchmark was not rerun.

record_new_worst_hit rounded the worst top-K hit up to the next second.
Split time ranges are inclusive whole seconds, so a split ending in the
same second as the worst hit can still hold a better document. Rounding
up discarded those splits and could return the wrong top K. Round down
instead (div_euclid, for both sort orders).
@fmassot
fmassot requested a review from a team as a code owner October 2, 2026 21:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T21:45:39.015172Z 0dcd4ed New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6067bfd6dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread quickwit/quickwit-search/src/leaf.rs Outdated
Comment thread quickwit/quickwit-search/src/leaf.rs Outdated
@fmassot fmassot changed the title Fix sort-by-timestamp-desc split pruning dropping same-second splits Fix timestamp split pruning by rounding metadata bounds outward Oct 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fcc3dc593

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1597 to +1599
// Newly indexed splits round their maximum timestamp up to whole seconds.
// For a worst hit at 1.5s, a split can do better only if its upper bound
// is at least 2s. Legacy truncated bounds can still cause false pruning.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep pruning safe for existing split metadata

For indexes containing splits created before this upgrade, the maximum timestamp remains truncated toward zero, and merge_time_range deliberately preserves that legacy bound. With a positive-time split whose recorded end is 1601 but which contains a document at 1601.9s, a current worst hit at 1601.758s still produces threshold 1602, so can_be_better skips the split and returns an incorrect top K. This affects existing indexes and mixed-version deployments—the common upgrade path—not merely historical edge cases; use a threshold compatible with legacy bounds or disable this pruning for legacy metadata.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are fine with that

@fmassot
fmassot requested a review from PSeitz October 10, 2026 21:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dcd4edcf3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +105 to +106
.div_euclid(1_000_000_000);
let end = quickwit_common::div_ceil(range.end().into_timestamp_nanos(), 1_000_000_000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Saturate outward bounds when reconstructing merge timestamps

When a timestamp reaches DateTime's nanosecond limits, this rounding stores -9_223_372_037 or 9_223_372_037 seconds, as the new extreme-value test explicitly permits. merge_time_range later passes those bounds to DateTime::from_timestamp_secs, but neither whole-second value fits in its i64 nanosecond representation, so a later merge can panic on overflow or reconstruct a wrapped, invalid range. Convert these metadata bounds back with saturating nanosecond multiplication (or equivalent clipping) before creating the merged DateTime range.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants