Query Graph Structure
The query graph is a directed graph where:- Nodes represent operations (queries, computations, control flow)
- Edges represent dependencies (data flow, execution order)
Node Types
Edge Types
Translation Process
Thetranslate function is the entry point:
query-compiler/src/translate.rs
Node Translation
TheNodeTranslator walks the graph and generates expressions:
Query Translation
Translating a database query node:Conditional Translation
Translating anif node creates a conditional expression:
Data Dependencies
Data dependencies flow through the graph via bindings:- Projected Dependencies
- Row Count Dependencies
When a node needs specific fields from a parent:Creates field-level bindings:
Query Building
TheQueryBuilder trait abstracts SQL generation:
In-Memory Processing
Some operations happen in-memory after data is fetched:Process expression:
Application-Level Joins
When relation joins can’t be done in SQL:- Executes parent query
- Extracts join keys from parent results
- Executes child query with
WHERE key IN (...) - Merges results in-memory based on
onconditions
Result Node Structure
The result structure describes how to shape the final output:Optimizations
The planner applies several optimizations:Subquery Elimination
Flatten nested queries where possible to reduce round-trips.
Projection Pushdown
Only select fields that are actually needed.
Predicate Pushdown
Push WHERE clauses as deep as possible.
Join Coalescing
Combine multiple joins when safe to do so.
Benchmarking Query Planning
Benchmark the compilation process:Makefile:
Query Graph Benchmarks
Benchmark just the graph building phase:Profiling
Profile a specific query:profile_query example which you can customize for your specific use case.
Playground
Explore query planning interactively:- Input a Prisma schema
- Write a GraphQL query
- See the generated expression tree
- Export Graphviz diagrams (if
dotis installed)
query-compiler-playground/Cargo.toml:
Next Steps
Overview
Return to architecture overview
WASM Build
Build the WebAssembly module