Micro-partition pruning and selective filters
Pruning skips micro-partitions whose metadata shows they cannot contain values needed by a query.
Your learning goal
Use min/max ranges and Query Profile to distinguish eligible partitions, matching rows and the benefit of selective business filters.
Understand the idea
A concrete example
The shop asks for January revenue. If a partition contains only February dates, its date range proves it cannot contribute. Snowflake can avoid reading its data for that predicate.
| Concept | What it means |
|---|---|
| Min/max metadata | A range of values recorded for a partition column. |
| Pruning | Exclude partitions that cannot match the filter. |
| Selectivity | How much input a predicate retains. |
| Column pruning | Read only the columns required by the query. |
Remember: Judge pruning against selectivity and projected columns. Measure the actual scan before choosing a storage optimization.
Explain it step by step · full theory
Learning goals and prerequisites
Use min/max ranges and Query Profile to distinguish eligible partitions, matching rows and the benefit of selective business filters.
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.
How the storage units arise
Snowflake automatically stores ordinary table data in compressed, column-oriented micro-partitions during loading and changes. A micro-partition is an immutable storage unit: a logical change produces new storage rather than editing its existing bytes in place. Retained older versions are part of the recovery story in Module 14.
Column-oriented means values from a column are organized together, helping read only relevant columns. Metadata records properties such as value ranges so the optimizer can exclude impossible candidates. Users do not manually create these ordinary table partitions. These descriptions are documented behavior; the illustrated ranges are conceptual.
Why a filter can save work
The shop asks for January revenue. If a partition contains only February dates, its date range proves it cannot contribute. Snowflake can avoid reading its data for that predicate.
An overlapping range means a partition may contain a match. It does not prove every row qualifies. The warehouse still evaluates the predicate on eligible data.
Inspect the scan
Open the TableScan operator and compare partitions scanned with total partitions, bytes scanned, columns and output rows. A narrow predicate reading nearly all partitions suggests overlap or an expression that prevents effective pruning.
A broad all-year report may legitimately scan most data. A high scan ratio is evidence to interpret against the requested date range, not an automatic defect.
Make the filter explicit
Half-open ranges express January as dates greater than or equal to January 1 and less than February 1. They also avoid accidentally excluding times later on the final day when filtering timestamps.
Functions on a filter column can change pruning opportunities. Snowflake may optimize some expressions, so compare actual scan statistics before claiming a direct range is faster.
Common mistakes and next action
Range overlap identifies possible matches. Row-level predicate evaluation still applies.
Judge pruning against selectivity and projected columns. Measure the actual scan before choosing a storage optimization.
Words used in this lesson
- Min/max metadata
- A range of values recorded for a partition column.
- Pruning
- Exclude partitions that cannot match the filter.
- Selectivity
- How much input a predicate retains.
- Column pruning
- Read only the columns required by the query.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Micro-partition pruning and selective filters
Partition ranges
Conceptual partition P1 covers January and P2 February. These ranges are teaching inputs.
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
- Partition ranges
Conceptual partition P1 covers January and P2 February. These ranges are teaching inputs.
P1 · Jan 1–31 → P2 · Feb 1–28 → Filter · January
- Skip impossible ranges
February cannot satisfy the January range, so P2 can be excluded.
P1 · candidate → P2 · pruned → Read January candidates
- Filter remaining rows
Eligible partitions may contain cancelled orders. Evaluate STATUS after locating candidate data.
Date candidates → STATUS = paid → Revenue 450
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.
Compare January filters
SELECT SUM(AMOUNT) FROM ORDERS
WHERE YEAR(ORDER_DATE)=2026 AND MONTH(ORDER_DATE)=1 AND STATUS='paid';
SELECT SUM(AMOUNT) FROM ORDERS
WHERE ORDER_DATE >= '2026-01-01'::DATE AND ORDER_DATE < '2026-02-01'::DATE
AND STATUS='paid';What to expect and why
Both return 450 on the fixture. Record separate query IDs and inspect scans on larger data. Equal results do not imply different physical plans.
Retrieve scan evidence
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
Compare only the intended query IDs. Zero scanned partitions may reflect reuse or metadata optimization rather than perfect physical clustering.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain why SELECT * for the whole year has a different pruning goal from one month of revenue.
Compare your reasoning
Judge pruning against selectivity and projected columns. Measure the actual scan before choosing a storage optimization.
Key takeaway
Judge pruning against selectivity and projected columns. Measure the actual scan before choosing a storage optimization.
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