0
0
Snowflakecloud~10 mins

Query profiling and the query plan in Snowflake - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Query profiling and the query plan
Submit SQL Query
Query Parser
Query Optimizer
Generate Query Plan
Execute Query Plan
Collect Profiling Data
Show Query Profile & Plan
The query is parsed, optimized, and a plan is created. The plan runs, collecting data. Finally, the profile and plan are shown.
Execution Sample
Snowflake
EXPLAIN USING TEXT SELECT * FROM orders WHERE amount > 100;
-- Then run
SELECT * FROM orders WHERE amount > 100;
Shows the query plan text, then runs the query to collect profiling data.
Process Table
StepActionDetailsResult
1Submit QuerySELECT * FROM orders WHERE amount > 100Query received by Snowflake
2Parse QueryCheck syntax and semanticsQuery parsed successfully
3Optimize QueryFind best plan for filtering amount > 100Query plan created with filter pushdown
4Generate Query PlanPlan includes scan of orders table with filterPlan ready for execution
5Execute Query PlanScan orders, apply filter amount > 100Rows matching condition retrieved
6Collect Profiling DataMeasure time, bytes scanned, rows processedProfiling data collected
7Show Query Profile & PlanDisplay execution steps and resource usageUser sees detailed query plan and profile
💡 Query execution completes and profiling data is available for analysis
Status Tracker
VariableStartAfter ParsingAfter OptimizationAfter ExecutionFinal
Query TextSELECT * FROM orders WHERE amount > 100ParsedOptimizedExecutedCompleted
Query PlanNoneNoneScan orders with filterUsed to fetch rowsAvailable for profile
Rows Processed000N rows matching filterN rows returned
Bytes Scanned000X bytes scannedX bytes recorded
Execution Time000Measured during executionTotal time recorded
Key Moments - 3 Insights
Why does the query plan show a filter operation before scanning all rows?
Because the optimizer pushes the filter down to reduce data scanned, as shown in step 3 and 4 of the execution table.
What does the profiling data tell us after query execution?
It shows resource usage like bytes scanned and execution time, helping understand query efficiency, as collected in step 6.
Why is the EXPLAIN command useful before running the query?
It shows the planned steps without running the query, so you can see how Snowflake will execute it, as in step 1 and 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the query plan created?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Check the 'Generate Query Plan' action in the execution table rows.
According to the variable tracker, when are rows processed counted?
AAfter Parsing
BAfter Optimization
CAfter Execution
DAt Start
💡 Hint
Look at the 'Rows Processed' variable values in the variable tracker.
If the filter condition changes, how does the query plan step change?
AThe plan stays the same
BThe filter operation in the plan updates
CParsing step changes only
DProfiling data changes only
💡 Hint
Refer to the 'Optimize Query' and 'Generate Query Plan' steps in the execution table.
Concept Snapshot
Query profiling shows how a query runs and uses resources.
The query plan is the step-by-step plan Snowflake makes to run the query.
Use EXPLAIN to see the plan before running.
Profiling data includes time, rows, and bytes scanned.
Optimizers push filters early to reduce work.
Profiling helps find slow or costly queries.
Full Transcript
When you submit a query in Snowflake, it first gets parsed to check for errors. Then the optimizer creates a plan to run the query efficiently. This plan includes steps like scanning tables and applying filters. When the query runs, Snowflake collects profiling data such as how many rows were processed, how many bytes were scanned, and how long it took. You can use the EXPLAIN command to see the query plan before running the query. This helps you understand how Snowflake will execute your query and can help you improve performance by adjusting your SQL or data. Profiling data after execution shows the actual resource usage and helps identify bottlenecks.