Module 15 · Lesson 8 of 14Detailed study · about 25 min

Memory pressure, spilling and redistribution

Spilling moves intermediate query data from memory to local disk and, when necessary, remote storage. It is a symptom of working data exceeding available memory.

Your learning goal

Connect wide joins, large sorts and skew to memory pressure, then choose between reducing work and increasing resources.

Understand the idea

A concrete example

A large join may build an in-memory structure for matching keys. A sort needs state to arrange rows. As intermediate size grows, execution may need disk storage and spend more time moving data.

Key ideas in simple English
ConceptWhat it means
Working setIntermediate data an operator needs while executing.
Local spillIntermediate data written to warehouse local storage.
Remote spillIntermediate data written to remote storage after local capacity is insufficient.
RedistributionMove rows between workers to perform distributed processing.
SkewUneven work or key frequency across workers.

Remember: Connect spill and network symptoms to specific intermediate data. Fix avoidable work before comparing the cost of more memory.

Explain it step by step · full theory

Learning goals and prerequisites

Connect wide joins, large sorts and skew to memory pressure, then choose between reducing work and increasing resources.

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.

Why memory becomes a bottleneck

A large join may build an in-memory structure for matching keys. A sort needs state to arrange rows. As intermediate size grows, execution may need disk storage and spend more time moving data.

Remote spill often deserves urgent investigation, but spill bytes alone do not prove the complete cause. With Query Acceleration enabled, a small remote-spill value can appear even without the same memory-pressure story. Interpret it with Profile and service settings.

Choose a remedy based on the operator

Remove accidental join growth, unnecessary columns and irrelevant rows first. Reduce avoidable window or sort work. If the remaining working set is necessary, compare an authorized larger warehouse under the same conditions.

Warehouse size is not a guaranteed speed multiplier. A computation with limited parallelism or time dominated by compilation may gain little. Compare credits and latency, not latency alone.

Distinguish network from storage

Distributed joins and aggregations can redistribute rows so related keys meet on workers. Wide rows and large intermediate output increase transfer. Skew can leave one worker processing a disproportionately large group.

The browser downloading a large result is another transfer stage. Reducing the final projection or exporting through an appropriate workflow addresses a different problem from warehouse-to-warehouse-worker redistribution.

Troubleshooting sequence

Save the query ID. Locate the spilling or network-heavy operator, inspect its input and output, and verify join grain. Test one change: fewer rows, narrower columns, a corrected join, or more memory.

Do not manufacture a spill with unbounded cross joins in a shared account. The learning fixture demonstrates the reasoning; an actual spill experiment requires an approved workload and cost limit.

Common mistakes and next action

Inspect the operator, query shape and service context before selecting a remedy.

Connect spill and network symptoms to specific intermediate data. Fix avoidable work before comparing the cost of more memory.

Words used in this lesson
Working set
Intermediate data an operator needs while executing.
Local spill
Intermediate data written to warehouse local storage.
Remote spill
Intermediate data written to remote storage after local capacity is insufficient.
Redistribution
Move rows between workers to perform distributed processing.
Skew
Uneven work or key frequency across workers.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 4

Memory pressure, spilling and redistribution

Input rows
Memory state
Process

Memory

A necessary working set fits available memory in this conceptual case.

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
  1. Memory

    A necessary working set fits available memory in this conceptual case.

    Input rows → Memory state → Process

  2. Local spill

    A larger intermediate set exceeds available memory and writes locally.

    Memory full → Local spill → Extra I/O

  3. Remote spill

    If local capacity is insufficient, remote I/O adds more work.

    Local capacity → Remote spill → Inspect cause

  4. Reduce or resize

    Correct row explosion first; then compare resources for necessary work.

    Correct grain → Smaller state → Measured resize

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.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. 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.
  3. 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.
  4. 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.

Find measured spill and timing

SQL · example
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

Inspect the exact business query IDs. Zero spill is a valid observation; this tiny fixture should not be expected to create memory pressure.

Inspect the shape of a sorted result

SQL · example
SELECT ORDER_ID,CUSTOMER_ID,AMOUNT
FROM ORDERS WHERE STATUS='paid' ORDER BY AMOUNT DESC,ORDER_ID;

What to expect and why

The projected paid rows have amounts 200, 150, 120, 100 and 80. Compare with a wide SELECT * only on an approved representative dataset, preserving the required output.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Should every remote-spill value immediately trigger a warehouse upgrade?

Try it yourself

Prepare a three-column evidence log: symptom, possible cause, controlled experiment.

Compare your reasoning

Connect spill and network symptoms to specific intermediate data. Fix avoidable work before comparing the cost of more memory.

Key takeaway

Connect spill and network symptoms to specific intermediate data. Fix avoidable work before comparing the cost of more memory.

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