Skip to content

MINUS, the union's fact dedup and COUNT(DISTINCT *) key a stored vector by decoding it #2483

Open

Description

@bplatz

MINUS, the union's fact dedup and COUNT(DISTINCT *) key a stored vector by decoding it: parsing its shard slice and widening each component to f64, once per row. DISTINCT, GROUP BY and the hash join use the vector's value key instead, which is a slice of its shard before the arena's identity table is built and a hash and canonical handle after.

From #2468's numbers (instructions:u, 100K subjects), MINUS on ?v across two predicates:

100K × 768 100K × 1536
before #2201 (keyed by handle, wrong once a vector repeats) 976M 1.43G
#2468 1.27G (1.30x) 2.01G (1.40x)

In a profile the hash is now about 10% of the run. Most of the rest of the gap is decoding.

What it takes

Each of the three keys rows its own way, so each needs a key that carries a vector's value key:

  • fluree-db-query/src/minus.rs: MinusKey(Vec<Binding>), built through normalize_for_key / normalize_for_key_cow.
  • fluree-db-query/src/union_fact.rs: the 16-byte KeyTerm set, which keeps an arena literal whole through normalize_for_key_cow.
  • fluree-db-query/src/aggregate.rs: CountDistinctAll, which keys whole solutions.

They need what the hashed operators already handle:

  • Keys from two arenas meet by a component compare only when their hashes match.
  • A failed shard read fails the query rather than keying two equal vectors apart, so each operator checks the key-read slot (ExecutionContext::check_key_reads) per batch.
  • On a residency host, the shards a batch reads are registered as missing first, so one retry round fetches them.

Done when

  • query_hot_vector_keying has MINUS cells before and after the identity tables are built, and the MINUS cost moves toward the hashed operators' ratio to main.
  • Answers are unchanged on SPARQL (and on JSON-LD for MINUS) for a vector repeated under one predicate and under two, before and after retractions. A failed vector read inside each operator fails the query.

Activity

  1. added
    P2
    area:query
    performance
    on Nov 21, 2026
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:queryperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions