Skip to content

Numeric MIN/MAX fast path can return a retracted value: it reads leaflet routing keys as the extremes #2398

Open

Description

@bplatz

Problem

minmax_numeric_post (fluree-db-query/src/fast_min_max_string.rs:258) answers MIN(?o) and MAX(?o) over one predicate from POST leaflet directories. It takes each leaflet's first_key as that leaflet's minimum and its last_key as its maximum (:283-310). The only checks are that the key's o_type is numeric and is the same across leaflets. Since 25e0721, those keys are routing bounds widened over the leaflet's retracted history (see #2394), so a retracted extreme of the same type can come back as the answer.

Found by reading the code on main at f42ea37. Not reproduced yet.

How a retracted value reaches the keys

  • Full build, MAX: a predicate's trailing retracted fact is buffered. At the segment flush it is committed into the outgoing leaflet (commit_pending_for_current_segment in push_record, fluree-db-binary-index/src/format/leaf.rs), and flush_leaflet widens that leaflet's last_key to cover it.
  • Full build, MIN: history that sorts before the predicate's first live row is committed into the leaflet that row opens, which widens its first_key.
  • Incremental build: a retracted extreme keeps widening the leaflet it was in.

The Cypher max(n.n) shape reaches the same function (fast_whole_graph_agg.rs:1046). String MIN/MAX (minmax_string_dict_post) is suspected of the same after an incremental retraction, but not traced.

Repro to run

  1. Give ex:n the values 0 to 9, plus 1000 and -5.
  2. Delete 1000 and -5.
  3. Index once with a full build, and separately with an incremental build.

The correct answers are MAX(?n) = 9 and MIN(?n) = 0. Reading the code predicts 1000 and -5. Compare against the general pipeline on the same view, using fluree_db_api::set_fast_paths_disabled(true).

Fix

Activity

  1. added this to the 5.0.0 milestone on Nov 14, 2026
  2. added
    bug
    P1
    area:query
    on Nov 14, 2026
  3. bplatz commented on Nov 20, 2026

    @bplatz
    ContributorAuthor

    The v5 half landed on next in #2402 (merged 2026-11-19, c63b329): numeric MIN/MAX reads the group of the predicate's first or last live row, and reads only that leaflet. Covered in it_leaflet_live_edges after full and incremental builds, and on a v4.2.6 fixture.

    Open for the main fix: read the live edge of the predicate's first (MIN) or last (MAX) leaflet.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1area:querybug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions