SnowPro Core Prep

Lab 13 · Domain 4 · You are Priya

Query Profile — don’t guess, look

Read every Teach first section before you copy SQL. When Kai says “make the warehouse bigger,” you open Query Profile first. Today: three caches, pruning, Profile nodes, and Query Acceleration Service awareness.

Business problem A board query feels slow. Morgan’s reflex: “Upsize to Medium.” Nobody checked whether the bottleneck is scanning almost every micro-partition, spilling to remote storage, or waiting on a join blast.
Solution you will practice Run a selective vs chunky query on LAB.ORDERS, open Snowsight Query Profile, name the three caches, and know when QAS helps (and when a bigger WH won’t).
Before
Resize first, think later
  • “Bigger WH = always faster”
  • No idea which cache hit
  • Pruning never mentioned
After
Profile-led triage
  • Name result / local / metadata cache
  • Check partitions scanned
  • Spill & QAS in your vocabulary

Episode 13 · Start here

Dev: “Show me the Profile before you burn credits.”

MorganManager — cost pressure
Just make it Medium. We have a board call in ten minutes.
DevCoach — explains why
If we’re scanning 95% of partitions, Medium costs more for the same IO shape. Profile first: TableScan, bytes spilled, join explosion — then decide scale up, clustering, or rewrite.

Exam trap: bigger warehouse ≠ more storage and ≠ automatic pruning.

See it — three caches

Cloud Services
Result cache

Exact same query text + unchanged data → reuse result. Often 0 warehouse credits.

Run identical SELECT twice → second may be instant
Warehouse
Local disk cache

SSD on WH servers holds data from recent scans. Helps warm queries on same WH.

Suspend WH → local cache goes cold
Cloud Services
Metadata cache

Micro-partition stats for pruning & planning — not your full result set.

Optimizer skips irrelevant partitions

See it — Profile words you’ll say

Pruning
Skip micro-partitions

Selective filters on clustered/min-max friendly columns scan fewer partitions.

WHERE STATUS = 'PENDING' on huge table
Nodes
TableScan · Join · Bloom

Profile graph shows operators. Bloom filters can reduce join probe work.

Snowsight → Query History → Profile
Spill
Memory → local/remote

Heavy sorts/hashes exceed memory → spill. Remote spill hurts latency.

Profile: bytes spilled to remote storage
QAS
Query Acceleration Service

Serverless boost for large scans/filters. Not a cure for bad joins or tiny tables.

ENABLE_QUERY_ACCELERATION on WH

Before Step 1

Kai opens the wrong panel

KaiAnalyst
I stared at the SQL worksheet. Where is the Profile?
PriyaYou
After the query finishes: Query History → click the query → Profile. Look at TableScan partitions scanned vs total.

1 Selective query (pruning-friendly shape)

What this does: Narrow filter. On a big table this is where pruning shines; our sample is tiny — still practice the Profile habit.

SQL · selective
USE ROLE ROLE_CORE_LAB_ADMIN;
USE WAREHOUSE WH_CORE_XS;
USE DATABASE ALPINE_RETAIL;
USE SCHEMA LAB;

SELECT ORDER_ID, CUSTOMER_ID, AMOUNT_USD, STATUS
FROM LAB.ORDERS
WHERE STATUS = 'PENDING';
✓ Open Profile — note TableScan / partitions (even if small)

Before Step 2

Contrast the chunky query

RileyEngineer
Aggregations that touch every row won’t be “fixed” by hoping for result cache on the first run.
DevCoach
Right. First run builds the plan and scans. Second identical run may hit result cache. Don’t confuse cache wins with “Medium made it fast.”

2 Broader query + result cache demo

What this does: Run an aggregate, then the same SELECT twice to feel result cache. RESULT_SCAN re-reads the last result without re-running the original SQL.

SQL · aggregate
SELECT STATUS, COUNT(*) AS N, SUM(AMOUNT_USD) AS TOTAL_USD
FROM LAB.ORDERS
GROUP BY STATUS
ORDER BY TOTAL_USD DESC;
SQL · result cache + RESULT_SCAN
SELECT ORDER_ID, AMOUNT_USD
FROM LAB.ORDERS
WHERE CUSTOMER_ID = 1
ORDER BY ORDER_ID;

-- Run the identical statement again, then:
SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
✓ You can explain result cache vs RESULT_SCAN

3 Clustering info (skip if not clustered)

What this does: SYSTEM$CLUSTERING_INFORMATION only helps on clustered (or naturally well-ordered) tables. Our tiny ORDERS sample usually isn’t worth clustering — know the function for the exam.

SQL · clustering (optional)
-- Only if you clustered a real table:
-- ALTER TABLE LAB.ORDERS CLUSTER BY (STATUS);
-- SELECT SYSTEM$CLUSTERING_INFORMATION('LAB.ORDERS', '(STATUS)');

-- QAS awareness (Enterprise+), don’t leave on for tiny labs:
-- ALTER WAREHOUSE WH_CORE_XS SET
--   ENABLE_QUERY_ACCELERATION = TRUE
--   QUERY_ACCELERATION_MAX_SCALE_FACTOR = 4;
✓ You can say when clustering depth / QAS matter

Exam presses further — say these out loud

Q1. What is RESULT_SCAN for?

Say: Query a previous result set by query ID without re-executing the original SQL — handy for post-processing the last statement’s output.

Q2. When will a bigger warehouse NOT help?

Say: When the bottleneck is poor pruning (scanning almost everything), waiting on cloud services only, tiny data already memory-resident, or a bad SQL shape (exploding joins). Profile first.

Q3. What does spill mean in Profile?

Say: Operators ran out of memory and wrote intermediate data to local or remote storage. Remote spill is expensive latency-wise — scale up or reduce memory pressure.

Q4. When consider Query Acceleration Service?

Say: Large scans/filters that can offload to QAS serverless acceleration — especially ad-hoc analytical queries. Not a substitute for fixing cardinality explosions.

Q5. Name the three caches and who “owns” them.

Say: Result cache (cloud services — reused results), local disk cache (warehouse SSDs — warm data), metadata cache (cloud services — partition stats for pruning/planning).

Priya’s wrap-up (say this out loud)
“I stopped guessing warehouse size. I ran selective vs broader queries, opened Query Profile, and named result cache, local disk cache, and metadata cache. I can explain pruning, spill, RESULT_SCAN, and when QAS is the right lever. Outcome: Domain 4 performance answers start with Profile, not panic resizing.”
Next Lab 14 — scale UP vs scale OUT, auto-suspend, multi-cluster warehouses.
← Lab 12 Lab 14 — warehouses →