Query Execution Flow
Snowflake · Warehouses & Performance
Theory
Every query follows the same path. Cloud Services first parses the SQL, resolves object names and checks that your role has the needed privileges. The optimizer then builds a plan, using micro-partition metadata (min/max values, row counts) to prune partitions that cannot match your filters. The plan is compiled and sent to the virtual warehouse, whose nodes scan the remaining partitions in parallel, join, aggregate and return the result through Cloud Services.
For example, WHERE order_date = '2024-03-01' on a table whose partitions each cover a few days lets the optimizer skip almost every partition before the warehouse reads a single byte.
Why we use it
Knowing which stage does what helps you tune. Compilation time, pruning, scanning, spilling and result return all show up separately in Query Profile, so you can tell which stage is the real bottleneck.
When to use it
Use this mental model whenever you read a Query Profile or decide how to fix a slow query: improve pruning for scan-heavy queries, size up for spilling, and simplify SQL when compilation itself is slow.
Parsing and Planning
Cloud Services first parses your SQL for syntax and checks your role's access rights, then the optimizer builds an execution plan using stored metadata, deciding which micro-partitions can be skipped entirely.
Compilation and Execution
The plan is compiled into physical execution steps, and only then does the assigned virtual warehouse actually scan data and compute results; Cloud Services then returns the final result set to you.
Why This Matters for Tuning
Understanding this flow explains why a warehouse that's too small slows the execution step, while poor filtering or clustering slows the planning step — they're different problems with different fixes.
The Full Query Path
User submits SQL │ ▼ ┌─────────────────────┐ │ CLOUD SERVICES │ 1. Parse SQL │ │ 2. Check permissions │ │ 3. Optimize query plan │ │ 4. Check result cache (hit → return instantly) └──────────┬──────────┘ │ (cache miss) ▼ ┌─────────────────────┐ │ VIRTUAL WAREHOUSE │ 5. Read micro-partitions (prune irrelevant) │ │ 6. Execute in parallel across nodes │ │ 7. Aggregate results └──────────┬──────────┘ ▼ Return Results
How it works
- SQL submitted
- Parse and check privileges in Cloud Services
- Optimize: prune micro-partitions using metadata
- Can the result come from the result cache? Yes: Return it with no warehouse used. No: Compile the physical plan.
- Warehouse executes the plan in parallel across its nodes
- Result returned to the client
Example
-- Parse → Optimize → Compile → Execute → Return resultsKey points
- Parsing, optimization and compilation happen in Cloud Services
- The optimizer uses metadata to prune unnecessary micro-partitions
- Execution is distributed across the nodes of the assigned warehouse
- Query Profile shows each operator's time and rows
- EXPLAIN shows the plan without executing the query