Skip to content

BE-515: HashQL: Remove OFFSET 0 materialization fence from generated query#8650

Draft
indietyp wants to merge 1 commit intobm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergencefrom
bm/be-515-hashql-remove-offset-0-materialization-fence-from-generated
Draft

BE-515: HashQL: Remove OFFSET 0 materialization fence from generated query#8650
indietyp wants to merge 1 commit intobm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergencefrom
bm/be-515-hashql-remove-offset-0-materialization-fence-from-generated

Conversation

@indietyp
Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

HashQL: Remove OFFSET 0 materialization fence from generated SQL

Problem

Each PostgreSQL island is wrapped in a CROSS JOIN LATERAL subquery. The subquery previously included OFFSET 0 as a materialization fence to prevent PostgreSQL's planner from inlining the CASE tree expression and duplicating it across each composite field access in the SELECT list.

The planner's cost estimate favors the fenced plan (lower estimated cost), but empirical benchmarks show the opposite for queries with conditional CASE trees:

Query Change (fenced → unfenced)
all_entities −11% (improved)
filter_by_uuid +10% (regressed)
diamond_cfg −5% (improved)
sequential_filters −72% (improved)
stress_test −77% (improved)

For multi-body queries with conditional branches, the materialization overhead exceeds the duplication cost by 3–4×. The fence helps modestly for simple single-expression queries without branching (filter_by_uuid), but is catastrophic for the common case.

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Existing test coverage for the HashQL eval Postgres module.

❓ How to test this?

  1. Checkout the branch.
  2. Run the existing test suite.
  3. Confirm all tests pass and query behavior is unchanged.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Apr 21, 2026 5:20pm
hashdotdesign-tokens Ready Ready Preview, Comment Apr 21, 2026 5:20pm
petrinaut Ready Ready Preview Apr 21, 2026 5:20pm

Copy link
Copy Markdown
Member Author

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.63%. Comparing base (dadf2c4) to head (9db238d).

Additional details and impacted files
@@                                            Coverage Diff                                            @@
##           bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence    #8650      +/-   ##
=========================================================================================================
+ Coverage                                                                  56.76%   63.63%   +6.86%     
=========================================================================================================
  Files                                                                        610     1163     +553     
  Lines                                                                      46028   129424   +83396     
  Branches                                                                    3077     4982    +1905     
=========================================================================================================
+ Hits                                                                       26130    82360   +56230     
- Misses                                                                     19644    46198   +26554     
- Partials                                                                     254      866     +612     
Flag Coverage Δ
apps.hash-ai-worker-ts 1.40% <ø> (ø)
apps.hash-api 0.00% <ø> (ø)
blockprotocol.type-system 40.84% <ø> (?)
local.claude-hooks 0.00% <ø> (?)
local.harpc-client 51.24% <ø> (?)
local.hash-graph-sdk 9.63% <ø> (ø)
local.hash-isomorphic-utils 0.00% <ø> (ø)
rust.antsi 0.00% <ø> (?)
rust.error-stack 90.87% <ø> (?)
rust.harpc-codec 84.70% <ø> (?)
rust.harpc-net 96.18% <ø> (?)
rust.harpc-tower 67.03% <ø> (?)
rust.harpc-types 0.00% <ø> (?)
rust.hash-codec 72.76% <ø> (?)
rust.hash-graph-api 2.52% <ø> (ø)
rust.hash-graph-authorization 62.34% <ø> (?)
rust.hash-graph-postgres-store 26.74% <ø> (?)
rust.hash-graph-store 37.76% <ø> (?)
rust.hash-graph-temporal-versioning 47.95% <ø> (?)
rust.hash-graph-types 0.00% <ø> (?)
rust.hash-graph-validation 83.45% <ø> (?)
rust.hashql-ast 87.23% <ø> (?)
rust.hashql-compiletest 28.31% <ø> (ø)
rust.hashql-core 82.25% <ø> (?)
rust.hashql-diagnostics 72.53% <ø> (?)
rust.hashql-hir 89.06% <ø> (?)
rust.hashql-mir 91.72% <ø> (ø)
rust.hashql-syntax-jexpr 94.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will not alter performance

✅ 80 untouched benchmarks


Comparing bm/be-515-hashql-remove-offset-0-materialization-fence-from-generated (9db238d) with bm/be-514-hashql-solver-iterate-forwardbackward-passes-to-convergence (dadf2c4)

Open in CodSpeed

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

Labels

area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

1 participant