Read Query Profile from the expensive operator outward
Query Profile shows the steps Snowflake took to run a query and where it spent its time. Each step is called an operator.
Your learning goal
Inspect scans, joins, filters, aggregates and sorts using operator rows, bytes, elapsed-time categories and query history.
Understand the idea
A concrete example
A sales report first reads orders, then matches each order to a customer and adds up sales by region. Query Profile lets you inspect each step. If the match step returns more orders than expected, check for duplicate customer records.
| Concept | What it means |
|---|---|
| TableScan | Read candidate table data and required columns. |
| Join | Combine rows according to a predicate. |
| Aggregate | Reduce input into groups and calculated results. |
| Sort | Order rows, often requiring memory and data movement. |
Remember: Connect each performance hypothesis to a specific operator and validate it with the exact completed query’s statistics.
Explain it step by step · full theory
Learning goals and prerequisites
Inspect scans, joins, filters, aggregates and sorts using operator rows, bytes, elapsed-time categories and query history.
Use the M15_LAB setup from lesson 1. Know SELECT, joins, aggregates and window functions from Modules 03–04. Follow the supplied examples with an authorized warehouse and an isolated learning role. Keep the same data and account context when comparing runs.
Find the dominant work
Open the saved regional-report query in Snowsight Query History and select its Profile. Follow the data flow from scans through the join to aggregation and output. Click an expensive operator and inspect its details.
A large percentage identifies where to investigate. Operator work can overlap in parallel, so adding every operator’s time is not a reliable way to reconstruct wall-clock time.
Translate symptoms into hypotheses
A TableScan with many partitions and few qualifying rows suggests examining pruning. A join with output far larger than inputs suggests checking key multiplicity and predicates. An expensive sort suggests reducing input or reviewing ordering requirements.
Aggregation cost can come from many distinct groups. Network time may indicate redistribution of large intermediate data. Diagnose the operator and its input, not merely the SQL clause that visually looks complicated.
Separate compilation and execution
Profile focuses on execution. Use query history for compilation, provisioning, queueing and elapsed-time context. If the warehouse was suspended, the first run may include startup effects.
A cached result can have a very different profile from an executed scan. Save IDs for the exact baseline and candidate runs, and keep a short observation log including data size and concurrent activity.
Common mistakes and next action
A planned operator graph does not measure the work of an actual execution.
Connect each performance hypothesis to a specific operator and validate it with the exact completed query’s statistics.
Words used in this lesson
- TableScan
- Read candidate table data and required columns.
- Join
- Combine rows according to a predicate.
- Aggregate
- Reduce input into groups and calculated results.
- Sort
- Order rows, often requiring memory and data movement.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Read Query Profile from the expensive operator outward
Scan
Read orders and customers. Inspect partitions, columns and qualifying rows.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Scan
Read orders and customers. Inspect partitions, columns and qualifying rows.
ORDERS scan → CUSTOMERS scan → Filter paid
- Join
Each paid order should match one customer in the fixture. Unexpected row growth needs investigation.
5 paid orders → 3 customer keys → 5 joined rows
- Aggregate
Group the matched amounts into two regional results.
east · 280 → west · 370 → 2 result rows
- Investigate
Select the operator matching the symptom and record one testable hypothesis.
Rows + bytes → Time category → Controlled next run
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual examples for L2_OBJECTS_LAB.M15_LAB. Select an authorized warehouse and a role with database/schema access and permission to create the lab objects. Setup runs once with fresh names. Optional paid services require their stated privileges and edition. SQL and performance timings have not been executed or measured for this lesson.
Inspect query-level measurements
SELECT QUERY_ID,QUERY_TAG,TOTAL_ELAPSED_TIME,COMPILATION_TIME,EXECUTION_TIME,
QUEUED_OVERLOAD_TIME,QUEUED_PROVISIONING_TIME,BYTES_SCANNED,
PARTITIONS_SCANNED,PARTITIONS_TOTAL,PERCENTAGE_SCANNED_FROM_CACHE,
BYTES_SPILLED_TO_LOCAL_STORAGE,BYTES_SPILLED_TO_REMOTE_STORAGE
FROM TABLE(L2_OBJECTS_LAB.INFORMATION_SCHEMA.QUERY_HISTORY_BY_SESSION(RESULT_LIMIT=>1000))
WHERE QUERY_TAG LIKE 'learnsnowflake_m15%'
ORDER BY START_TIME DESC;What to expect and why
Times are account observations in milliseconds. Examine the saved query IDs and their conditions.
Inspect operator statistics for a completed query
-- Set this to an actual completed SELECT ID from your run:
-- SET inspected_query_id='<query-id>';
-- SELECT * FROM TABLE(GET_QUERY_OPERATOR_STATS($inspected_query_id));
EXPLAIN USING TEXT
SELECT c.REGION,SUM(o.AMOUNT) FROM ORDERS o
JOIN CUSTOMERS c ON o.CUSTOMER_ID=c.CUSTOMER_ID
WHERE o.STATUS='paid' GROUP BY c.REGION;What to expect and why
EXPLAIN provides a plan without proving actual runtime. GET_QUERY_OPERATOR_STATS requires a supported recent completed query and appropriate visibility. Use actual Profile to confirm the expensive path.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Find the scan, join and aggregate of your regional report and explain each output count.
Compare your reasoning
Connect each performance hypothesis to a specific operator and validate it with the exact completed query’s statistics.
Key takeaway
Connect each performance hypothesis to a specific operator and validate it with the exact completed query’s statistics.
Connect this lesson to the learning path
Official sources and curriculum
Module 15 · See module scope
By Rohit Ray · Independent educational lesson · Explore this visual lab