Skip to content

perf(executor): GROUP BY over a BIND counts per input first under ids (#11) - #175

Open
MathiasVDA wants to merge 9 commits into
mainfrom
claude/project-thread-n3oul3
Open

MathiasVDA wants to merge 9 commits into
mainfrom
claude/project-thread-n3oul3

Conversation

@MathiasVDA

@MathiasVDA MathiasVDA commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What and why

#11, the follow-up noted in #172: under --executor ids, a GROUP BY over a computed key was slower than under spareval. One example is BIND(?q * 2 AS ?k) … GROUP BY ?k, which took 16 to 21 ms against 11 to 14 on 133k orders.

The cause was in count::rewrite, which tried the grouped counts before the eager grouping.

  • Under spareval the grouped counts can't take a BIND. So the eager grouping (eager_group) answered the query: it counts the rows per distinct ?q, then computes the BIND once per value (100 values).
  • Under ids the grouped counts now cover the BIND. So they answered first, computing the expression for each of the 133k rows before grouping.

Now, under the id executor, a Group whose input is a BIND (or a FILTER on one) tries the eager grouping first. That step already gives up when there are nearly as many inputs as rows, and then the grouped counts run as before. Under spareval nothing changes.

How it was tested

  • tests/id_rows.rs GROUPS has three new cases, each compared with the evaluator:

    • a count by ?q * 2;
    • SUM and MAX by ?q - 3 with a filter on it;
    • COUNT(DISTINCT ?q / 2) per customer.
  • Oracle with ids as the default: all suites pass, apart from the two known plan-shape assertions in bind_keyed_lookup.

  • 133k orders, result cache off, three runs, same answers:

    query spareval ids before ids after
    BIND(?q * 2 AS ?k) … GROUP BY ?k 11–15 ms 16–21 ms 11–14 ms
    BIND(ABS(?q) AS ?k) … GROUP BY ?k 11–14 ms 20 ms 11–12 ms
    SUM(?q * 2) per customer, top 5 (many inputs, unchanged) 164 ms 29 ms 29 ms
  • cargo fmt --check and cargo clippy -p tripletrail --all-targets -D warnings pass.

Documentation

  • docs/store.md: the grouping paragraph.
  • docs/server.md: the --executor list now names division, ABS/CEIL/FLOOR/ROUND, the xsd:integer and xsd:decimal casts, IF and COALESCE, and points to docs/store.md for the full list. This is the follow-up the review of perf(executor): IF and COALESCE on term ids (#11) #172 asked for.
  • CHANGELOG: a line under Unreleased / Changed.

Docs checked:

  • In the repo: the guide's --executor ids section (13-production.md) and the README say nothing about grouping plans or kernel lists, and stay true.
  • On the website: tripletrail-website has no page on query plans, so it needs no change.

Main, with #172, is merged in.

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.

1 participant