What you will be able to do
- Open the Query Profile for any past query and find its most expensive operator nodes
- Use the Query Insights pane to identify the condition slowing a query
- Tell local spilling from remote spilling and pick the right fix
- Spot ineffective pruning by comparing partitions scanned with partitions total
- Recognise an exploding join and trace it to its join condition
Key concept
Query Profile — The Query Profile is a per-query view of the execution plan. Each operator, such as TableScan, Join or Aggregate, appears as a node with its own statistics, so you can see which step took the time and why.
1.Opening the Query Profile for any query
Evaluating a slow query starts with its Query Profile. The profile shows how Snowflake actually ran the query as a tree of operator nodes, and the statistics on each node tell you where the time went. Guessing from the SQL text alone can't do that.
The profile is stored with the query, not with the worksheet, so you can open it after the user's session has closed. In Snowsight:
- Select Monitoring » Query History in the navigation menu.
- Select the query ID of the query.
- Select the Query Profile tab.
The first place to look is the Most Expensive Nodes pane, which ranks operators by execution time. From a node you can drill into the share of its time spent in each processing category: Processing (CPU), Local Disk IO, Remote Disk IO, Network Communication, Synchronization and Initialization. A node that spends most of its time in Remote Disk IO is telling you something different from one that is busy in Processing.
The same numbers are available in SQL. The GET_QUERY_OPERATOR_STATS table function returns one row per operator, with columns such as OPERATOR_TYPE, OPERATOR_STATISTICS and EXECUTION_TIME_BREAKDOWN. Because it is a table function, you wrap it in TABLE(), for example SELECT * FROM TABLE(GET_QUERY_OPERATOR_STATS(last_query_id())).
Checkpoint 1 of 8· Put it in order
A user says a query they ran yesterday was slow, and their session has since closed. Put the Snowsight steps for opening that query's Query Profile in order.
- 1.Select the query ID of the slow query
- 2.In the navigation menu, select Monitoring » Query History
- 3.Select the Query Profile tab
The profile is stored with the query, not the worksheet. You reach it from Monitoring » Query History by opening the query by its ID and then its Query Profile tab, even after the session has closed.
“In the navigation menu, select Monitoring » Query History.”Source: docs.snowflake.com
2.Query insights: Snowflake's own diagnosis
When Snowflake detects a condition that affects a query's performance, it records a query insight. Each insight gives a message about the condition, the part of the query that caused it, and a suggested next step. In the Query Profile tab, nodes that have insights are highlighted. The Query Insights pane on the right lists every instance, and View opens the details. The same data can be queried from the QUERY_INSIGHTS view, where the INSIGHT_TOPIC column groups the insights by topic.
| INSIGHT_TOPIC | Example insight | What it points at |
|---|---|---|
| TABLE_SCAN | No filter on table scan / Filter not applicable / Filter not selective | The scan reads more data than the query needs |
| TABLE_SCAN | LIKE filter with leading wildcard | A pattern such as '%abc' forces a large scan |
| JOIN | Join with no join condition / Exploding join | A join produces far more rows than its inputs |
| AGGREGATION | Unnecessary aggregation | DISTINCT or GROUP BY that changes nothing |
| UNION | Unnecessary UNION [ DISTINCT ] clause | Disjoint inputs; UNION ALL would do |
| WAREHOUSE | Remote spillage / Query was in the queue for the warehouse for too long | The warehouse lacked memory or capacity |
Some queries get no insights at all. Queries that reuse results, EXPLAIN queries, queries involving secure objects, queries against hybrid tables, queries generated by Native Apps and queries whose plan takes multiple steps all fall into this group. Snowflake also skips the "filter not selective" insight for queries accelerated by the query acceleration service. So an empty Query Insights pane does not prove the query is healthy. It may just mean the query is one Snowflake doesn't analyse.
Checkpoint 2 of 8· Check yourself
An analyst's query against a secure view ran for 20 minutes. When you open its Query Profile, the Query Insights pane is empty. What should you conclude?
Queries involving secure objects are among those Snowflake doesn't analyse. An empty pane only means no insight was produced, not that the query is healthy, so diagnose it from the profile's nodes, such as Most Expensive Nodes.
“Insights are not produced for: Queries for which the query plan takes multiple steps to finish. Queries involving secure objects.”Source: docs.snowflake.com
Sources4
3.Bytes spilled to local and remote storage
Spilling happens when an operation's intermediate results don't fit in the warehouse's memory. Snowflake writes the overflow to disk in two stages, and each stage is slower than the one before. First it spills to the warehouse's local disk. If even that isn't enough, it spills to remote cloud-provider storage, which makes performance worse again.
The Query Profile's statistics pane shows both stages under Spilling: "Bytes spilled to local storage" and "Bytes spilled to remote storage". To find the operator responsible, look for the node that has these statistics, usually a heavy Aggregate, Sort or Join. Its execution-time breakdown will show the time going to Local Disk IO or Remote Disk IO. Local spilling alone already slows the query a lot. A large remote figure is the more serious case, because those intermediate results are going over the network to cloud storage instead of to the warehouse's own disk.
Spilling is a memory problem inside one query, so it has two fixes. The first is a larger warehouse, which gives that query more memory and local storage. The second is processing the data in smaller batches when resizing isn't an option. Spillage is the symptom that calls for scaling up rather than out (Scale up vs scale out). Adding clusters to a multi-cluster warehouse lets more queries run at once, but it gives no single query more memory. Once a resize is in place, rerun the query. If both spill counters drop to zero, the working set now fits in memory.
Checkpoint 3 of 8· Check yourself
Two nightly jobs show spilling in their Query Profiles. Job A spilled 30 GB to local storage and nothing to remote storage. Job B spilled 4 GB to local storage and 3 GB to remote storage. Which job has the more serious memory problem, and why?
Local disk is the first overflow tier. A query spills to remote cloud-provider storage only when it needs even more memory than that, and performance gets worse again. So any significant remote spilling is the more serious sign, even if the byte count is smaller.
“If the query requires even more memory, it spills onto remote cloud-provider storage, which results in even worse performance.”Source: docs.snowflake.com
Checkpoint 4 of 8· Exam question
An analyst runs a large GROUP BY aggregation on an X-Small warehouse. The Query Profile statistics pane reports 40 GB under "Bytes spilled to local storage" and the Aggregate node dominates execution time. What is the most effective first change to try?
Correct answer: A — Resize the warehouse to a larger size so more memory becomes available for the aggregation step to run in.
- A. Local spilling happens when the intermediate working set does not fit in the warehouse's allocated memory, so increasing the warehouse size gives the aggregation more memory and directly reduces spilling. This is the standard first remedy Snowflake documentation recommends for spill-heavy queries.
- B. Multi-cluster warehouses add clusters to handle concurrent queries queuing for resources, but they do not give a single query more memory per cluster, so this does not address spilling within one aggregation.
- C. Trimming output columns can shrink the final result set, but the spill here is driven by the aggregation's intermediate working set on the grouping keys, not by the number of returned columns, so this has little effect.
- D. The result cache only helps when an identical query is reissued against unchanged data; it does nothing for the first, still-spilling execution of this aggregation.
Checkpoint 5 of 8· Exam question
Two completed queries both show spilling in their Query Profile statistics pane. Query 1 shows only nonzero "Bytes spilled to local storage." Query 2 shows a large nonzero value under "Bytes spilled to remote storage." Which statement correctly compares their severity?
Correct answer: B — Query 2 carries the larger penalty, since remote spilling writes intermediate data to cloud storage, not local SSD cache.
- A. Spilling and the result cache are unrelated mechanisms; remote spilling reflects memory and local-disk pressure during execution and has no dependency on whether a result was previously cached.
- B. Remote spilling means the local disk cache on the warehouse nodes is also full, forcing intermediate data onto slower cloud storage over the network, which is far more expensive than local spilling and is treated as the more urgent tuning signal.
- C. Local spilling can occur on a warehouse of any size once the working set exceeds available memory and local disk cache; it is not gated on the warehouse already being at maximum size, so this reasoning is incorrect.
- D. Local and remote spilling are not equivalent in cost: remote spilling adds network round trips to cloud storage on top of any compression, so the two tiers do not perform the same.
4.Spotting inefficient pruning
Pruning is how Snowflake skips micro-partitions that can't contain matching rows, using the metadata kept for each partition (Micro-partitions, pruning and clustering depth). Its effect shows in the Pruning statistics on a TableScan node. Partitions scanned is the number of partitions read, and Partitions total is the number of partitions in the table.
The ratio between the two tells you how well pruning worked. Suppose a report filters on a single date but the TableScan shows 9,800 partitions scanned out of 10,000. The filter cut out almost nothing at the storage level, and the query paid to read nearly the whole table. This isn't spilling, which shows up in different counters, and it isn't queuing, which happens before execution starts. When pruning works, the scanned count is a small fraction of the total.
Query insights flag the scan-side causes. No filter on table scan means there is no WHERE clause at all. Filter not applicable means the WHERE clause removed no rows. Filter not selective means it removed only a few. LIKE filter with leading wildcard means a pattern such as '%abc' forced a large scan. In each case the suggested next step is a more selective condition. For leading wildcards that can't be avoided, Snowflake suggests search optimization. The positive insight Filter uses clustering key confirms that a query benefited from filtering on the table's clustering key. Fixing poor pruning with clustering is covered in query optimization.
Checkpoint 6 of 8· Match them up
Query insights under the TABLE_SCAN topic each point to a different scan-side cause of poor pruning. Match each insight to the condition it reports.
Tap a term, then the definition that fits it.
All four mean the scan read more data than it needed to. The difference is the cause: there is no WHERE clause, the WHERE clause removes nothing, it removes only a few rows, or a pattern starting with a wildcard defeats pruning. For the first three the fix is a more selective condition. For an unavoidable leading wildcard, Snowflake suggests search optimization.
“Unlike the Filter not applicable insight, this insight indicates that the WHERE clause is filtering out some rows but it could have been more selective.”Source: docs.snowflake.com
Checkpoint 7 of 8· Exam question
In the Query Profile for a slow report query, a TableScan node shows "Partitions scanned: 9,800" out of "Partitions total: 10,000" even though the query filters on a single date column. What does this indicate?
Correct answer: C — Pruning is largely ineffective, since nearly every micro-partition had to be read despite the date filter.
- A. Partitions scanned versus partitions total is a pruning metric on the TableScan node, not a spill metric; spilling is reported separately in the statistics pane under bytes spilled to local or remote storage.
- B. Queuing time is reported separately as time the query waited before it started executing; the scanned-partition count describes how much data a running scan touched, not resource contention.
- C. When partitions scanned is close to partitions total despite a selective filter, the filtered column's value ranges are spread across most micro-partitions, so pruning cannot eliminate them and the scan reads nearly the whole table.
- D. Snowflake's pruning is designed to skip micro-partitions whose min/max metadata rules out the filter predicate; scanning almost everything is a sign pruning failed for this data layout, not expected default behavior.
5.Exploding joins
An exploding join is a Join node whose output has far more rows than its inputs. In the profile, compare the rows going into the Join with the rows coming out. A join that multiplies rows forces every operator above it to process that inflated set. It also tends to cause spilling, because the extra rows have to fit somewhere.
The usual cause is the join condition. With no condition at all, the join becomes a cross join that returns every combination of rows. Snowflake flags this as Join with no join condition. A wrong or too-loose condition produces Exploding join (not nested), meaning a join of two data sets returns many more rows than they contain. Exploding join (nested join) means a join that consumes the output of other joins is exploding. The problem then usually sits in the child joins' conditions, and the fix belongs there. A WHERE clause on a subquery feeding the join can also cut the rows. A filter applied several steps later removes rows only after the expensive join has already made them.
To check a complex query in SQL, use GET_QUERY_OPERATOR_STATS to compute each Join operator's ratio of output rows to input rows. Any join with a large multiple is a candidate, and its condition should be checked first.
SELECT operator_id,
operator_attributes,
operator_statistics:output_rows / operator_statistics:input_rows AS row_multiple
FROM TABLE(GET_QUERY_OPERATOR_STATS($lid))
WHERE operator_type = 'Join'
ORDER BY step_id, operator_id;A different JOIN insight, Join with inefficient join condition, is not about row counts. It means a complex condition is evaluated after the data sets are joined, when evaluating it before the join would reduce the work. The suggested fix is to simplify the condition.
Checkpoint 8 of 8· Check yourself
A reporting query joins five tables. Its Query Profile flags "Exploding join (nested join)" on the top Join node, which takes its input from two other joins. Three operators later, a Filter removes 95% of the rows. What fix does this insight point to?
A nested exploding join usually means the child joins' conditions are wrong, so the fix belongs there or in filtering their inputs earlier. The extra rows are created and paid for at the join, before any later Filter runs. A bigger warehouse only treats the spilling that follows.
“To prevent the join from producing more rows than the joined tables contain, add or change the join conditions for the child joins.”Source: docs.snowflake.com
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“It includes a Most Expensive Nodes pane that identifies the operator nodes that are taking the longest to execute.”
↩︎ Opening the Query Profile for any query“You can programmatically access the performance statistics of the Query Profile by executing the GET_QUERY_OPERATOR_STATS function.”
↩︎ Opening the Query Profile for any query“The Query Profile allows you to examine which parts of a query are taking the longest to execute.”
↩︎ Key concept“In the navigation menu, select Monitoring » Query History.”
↩︎ Checkpoint - 2.
“Remote Disk IO — time when the processing was blocked by remote disk access.”
↩︎ Opening the Query Profile for any query“Bytes spilled to remote storage — volume of data spilled to remote disk.”
↩︎ Bytes spilled to local and remote storage“Partitions scanned — number of partitions scanned so far.”
↩︎ Spotting inefficient pruning - 3.
“Because this function is a table function, you must use it in a FROM clause and you must wrap it in TABLE().”
↩︎ Opening the Query Profile for any query“After you identify the exploding joins, you can review each join condition to verify that the condition is correct.”
↩︎ Exploding joins - 4.
“In Query Profile tab under Query History, you can view the insights for a query. The nodes that have corresponding insights are highlighted.”
↩︎ Query insights: Snowflake's own diagnosis“Snowflake does not produce the “filter not selective” insight for queries that are accelerated by the query acceleration service.”
↩︎ Query insights: Snowflake's own diagnosis“A WHERE clause doesn’t filter out any rows, which means that the query might scan more data than intended.”
↩︎ Spotting inefficient pruning“If you need to specify a pattern that starts with a wildcard, consider enabling search optimization for more efficient pattern matching.”
↩︎ Spotting inefficient pruning“The join is missing the join condition. The result is a cross join, which returns every possible combination of rows.”
↩︎ Exploding joins“A join that includes the output of at least one other join is returning many more rows than are in the tables being joined.”
↩︎ Exploding joins“If using a larger warehouse is not an option, change the query to process data in smaller batches.”
↩︎ Exam trap 1“This might indicate a problem with the join conditions for the child joins.”
↩︎ Exam trap 3“Insights are not produced for: Queries for which the query plan takes multiple steps to finish. Queries involving secure objects.”
↩︎ Checkpoint“Unlike the Filter not applicable insight, this insight indicates that the WHERE clause is filtering out some rows but it could have been more selective.”
↩︎ Checkpoint“To prevent the join from producing more rows than the joined tables contain, add or change the join conditions for the child joins.”
↩︎ Checkpoint - 5.
“Performance degrades drastically when a warehouse runs out of memory while executing a query because memory bytes must “spill” onto local disk storage.”
↩︎ Bytes spilled to local and remote storage“You can use the Query Profile to identify which operation nodes are causing data to spill to storage.”
↩︎ Bytes spilled to local and remote storage“If the query requires even more memory, it spills onto remote cloud-provider storage, which results in even worse performance.”
↩︎ Exam trap 2“Using a larger warehouse (effectively increasing the available memory/local storage space for the operation)”
↩︎ Prediction“If the query requires even more memory, it spills onto remote cloud-provider storage, which results in even worse performance.”
↩︎ Checkpoint