Skip to content

Range semijoin prunes POST leaflets by o_key without checking the key's o_type #2399

Open

Description

@bplatz

Problem

The range semijoin skips a POST leaflet when last < lo || first > hi (fluree-db-query/src/range_semijoin.rs:693-700). It reads o_key from the leaflet's first_key/last_key without checking that those keys' o_type is the leaflet's o_type_const.

POST segments by predicate only. So on the same predicate, a retracted value of another type can widen last_key into that type (see #2394 for the widening). For example, a string on an integer predicate does this, because XSD_STRING (0x8000) sorts after the integer types. last.o_key is then a string id compared against integer bounds, and a leaflet that holds matching rows can be skipped.

post_o_key_bounds in fluree-db-query/src/join.rs:3586 does the same prune correctly. It compares (p_id, o_type) before using o_key, and treats a key of another type as an open bound.

Found by reading main at f42ea37. Not reproduced, and I haven't confirmed which query shapes reach this operator (the BSBM-Q5-style range fold).

Repro to try

  1. Give ex:n 20 integer values and one string.
  2. Delete the string.
  3. Run a full build.
  4. Run a ?p ex:n ?sim FILTER(?sim > ?orig - 3 && ?sim < ?orig + 3) shape, and compare it against fluree_db_api::set_fast_paths_disabled(true) on the same view.

Fix

Use post_o_key_bounds here instead of the raw o_key comparison. This needs no format change.

Related, performance only: the numeric-compare lane's first.o_type != raw_otype check (fluree-db-query/src/fast_count.rs:544) permanently declines for any predicate that has ever had a retracted value of another type.

Activity

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

    @bplatz
    ContributorAuthor

    Fixed on next by #2402 (merged 2026-11-19, c63b329): the range semijoin prunes with post_o_key_bounds, as the batched join already did. Covered in it_leaflet_live_edges.

    The fix needs no format change, so it can go to main as is. Open until it does.

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

    P2area:querybug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions