Snowflake Data Cloud
Module 03 • How Tables Work

Tables, Tuning & Loading

You can't add an index and you can't declare partitions. So how do you make a 5 TB table fast? This module covers the tools Snowflake gives you instead, a repeatable tuning checklist, and the exact setup to load files from S3 and Azure.

~60 min AWS + Azure walkthroughs Tuning checklist
01

Table types: pick the right one first

TypeTime TravelFail-safeLives untilUse it for
Permanent (default)0–90 days7 daysDroppedProduction data you can't easily rebuild
TRANSIENT0–1 dayNoneDroppedStaging, intermediate ELT tables, anything re-creatable. Saves Fail-safe storage.
TEMPORARY0–1 dayNoneEnd of sessionScratch work inside one session or procedure
ExternalNoneNoneDropped (files stay)Querying files in your lake without loading them
DynamicYesYesDroppedDeclarative pipelines that refresh to a target lag (Module 04)
IcebergYes (Snowflake-managed)NoDroppedOpen-format tables in your own bucket that other engines can read
HybridLimited—DroppedRow-oriented, indexed, enforced PK/FK for low-latency operational lookups

Cheap win: create staging schemas as CREATE TRANSIENT SCHEMA staging;. Every table in it is transient by default, so you never pay 7 days of Fail-safe on data you reload every night.

02

Clustering keys

Tell Snowflake which columns to keep co-located so pruning keeps working as the table grows and changes.

Snowflake stores rows in the order they arrive. For an append-only fact table loaded daily, that is already sorted by date, so date filters prune perfectly. Clustering decays when you load from many sources at once, backfill old dates, or run lots of UPDATE/MERGE. A clustering key tells the Automatic Clustering service (serverless, billed separately) to re-organise micro-partitions in the background.

Add a clustering key when…
  • The table is large (multi-TB, thousands of micro-partitions).
  • Queries mostly filter or join on the same column(s).
  • The Query Profile shows poor pruning on those filters.
  • The table is queried far more than it is modified.
Don't when…
  • The table is small (a few GB). Full scans are already cheap.
  • It is churned constantly. Reclustering cost will never settle.
  • Natural load order already matches the filter, as with event date.
  • Queries filter on many different columns. Consider Search Optimization instead.

Choosing the key

  • Use 1–3 columns (4 at most), ordered from lower to higher cardinality.
  • Mind cardinality. Too few distinct values (a boolean) gives no pruning, and too many (a raw timestamp or UUID) makes clustering expensive. Use an expression to reduce it, for example TO_DATE(event_ts) instead of event_ts.
  • Pick what queries filter on, not what "feels" like a key.
-- Define at creation or later
CREATE TABLE events (event_ts TIMESTAMP_NTZ, tenant_id NUMBER, payload VARIANT)
  CLUSTER BY (TO_DATE(event_ts), tenant_id);

ALTER TABLE events CLUSTER BY (TO_DATE(event_ts), tenant_id);

-- How well clustered is it? (average_depth near 1 = great)
SELECT SYSTEM$CLUSTERING_INFORMATION('events');

-- Pause / resume background reclustering (e.g. during a big backfill)
ALTER TABLE events SUSPEND RECLUSTER;
ALTER TABLE events RESUME RECLUSTER;

-- What has Automatic Clustering cost me?
SELECT table_name, SUM(credits_used) AS credits
FROM snowflake.account_usage.automatic_clustering_history
WHERE start_time >= DATEADD(day, -30, CURRENT_TIMESTAMP())
GROUP BY 1 ORDER BY 2 DESC;

-- Free alternative for a one-time fix: rewrite sorted
INSERT OVERWRITE INTO events SELECT * FROM events ORDER BY TO_DATE(event_ts), tenant_id;

See it visually in the pruning simulator in Module 02.

03

Indexes? Partitions? What Snowflake has instead

Short answer for interviews

Standard Snowflake tables have no user-defined indexes and no user-defined partitions. Micro-partitioning is automatic, and min/max metadata acts like a built-in, always-on "zone map" index. You influence layout with clustering keys, and you speed up specific access patterns with the services below.

NeedSnowflake featureNotes
Range filters on a big table (dates, IDs)Clustering keyImproves pruning. Serverless reclustering cost.
Needle-in-haystack lookups (WHERE email = ?), substring and LIKE, VARIANT fields, geoSearch Optimization ServiceBuilds a persistent search access path. Enterprise+. Storage plus serverless maintenance cost.
The same expensive aggregate queried repeatedlyMaterialized viewSingle-table, auto-maintained. Enterprise+.
Multi-table transforms kept freshDynamic tableJoins allowed, refreshed to a target lag.
Occasional huge scans that slow everyone downQuery Acceleration ServiceOffloads parts of eligible scans to serverless compute.
Real indexes, enforced primary keys, fast single-row reads and writesHybrid tablesRow store with primary key and secondary indexes. Built for operational workloads.
Partitioning files in a data lakeExternal tables / IcebergPartition columns derived from the file path. This is the one place you declare partitions.
ALTER TABLE customers ADD SEARCH OPTIMIZATION ON EQUALITY(email, phone);
ALTER TABLE logs      ADD SEARCH OPTIMIZATION ON SUBSTRING(message);
DESCRIBE SEARCH OPTIMIZATION ON customers;

Constraints are not enforced on standard tables, except NOT NULL. A PRIMARY KEY won't stop duplicates. Deduplicate in your MERGE or with QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1. Declaring keys is still useful: BI tools read them, and the optimizer can use declared RELY constraints for join elimination.

04

Performance tuning: a repeatable checklist

Always start from the Query Profile (Snowsight → Query History → the query → Query Profile).
Symptom in Query ProfileLikely causeFix
Partitions scanned ≈ partitions totalFilter can't prune: wrong column, function on column, or poor clusteringFilter on the raw column (ts >= '2026-01-01', not YEAR(ts) = 2026). Add a clustering key or Search Optimization.
Bytes spilled to local / remote storageJoins, sorts or aggregations don't fit in memoryScale up the warehouse, reduce rows and columns earlier, or split the query.
Join output rows » input rows ("exploding join")Missing or duplicate join keysFix the join condition and deduplicate dimension rows.
Long queued time, short executionWarehouse saturated by concurrencyMulti-cluster (scale out) or separate warehouses per workload.
Long compilation timeHuge SQL, many views, or thousands of tiny micro-partitionsSimplify the SQL and compact tiny files and partitions.
TableScan dominates with good pruningSelecting too many columnsAvoid SELECT *. It is a column store.
A few huge scans slow a shared warehouseOutlier queriesEnable Query Acceleration, or route them to their own warehouse.
Big ORDER BY at the endGlobal sort of millions of rowsSort only what you return (LIMIT), and use QUALIFY for top-N per group.
SELECT query_id, user_name, warehouse_name, warehouse_size,
       total_elapsed_time / 1000      AS seconds,
       partitions_scanned, partitions_total,
       bytes_spilled_to_remote_storage AS remote_spill,
       queued_overload_time / 1000     AS queued_s,
       LEFT(query_text, 120)           AS sql_head
FROM snowflake.account_usage.query_history
WHERE start_time >= DATEADD(day, -7, CURRENT_TIMESTAMP())
  AND execution_status = 'SUCCESS'
ORDER BY total_elapsed_time DESC
LIMIT 25;

-- Turn on Query Acceleration for a warehouse (Enterprise+)
ALTER WAREHOUSE bi_wh SET ENABLE_QUERY_ACCELERATION = TRUE
                          QUERY_ACCELERATION_MAX_SCALE_FACTOR = 8;
05

External tables

An external table is a read-only table definition over files that stay in your bucket. Snowflake stores only metadata: the file list and partition values. Every row arrives as one VALUE VARIANT column. You add virtual columns that extract fields and partition columns parsed from METADATA$FILENAME.

-- Files land as s3://acme-lake/clicks/dt=2026-10-15/part-0001.parquet
CREATE OR REPLACE EXTERNAL TABLE ext_clicks (
    dt       DATE    AS (TO_DATE(SPLIT_PART(SPLIT_PART(METADATA$FILENAME, 'dt=', 2), '/', 1))),
    user_id  NUMBER  AS (VALUE:user_id::NUMBER),
    url      STRING  AS (VALUE:url::STRING)
)
PARTITION BY (dt)
LOCATION     = @lake_stage/clicks/
FILE_FORMAT  = (TYPE = PARQUET)
AUTO_REFRESH = TRUE;    -- uses cloud event notifications to pick up new files

SELECT dt, COUNT(*) FROM ext_clicks WHERE dt = '2026-10-15' GROUP BY dt;  -- prunes folders

Good for

  • Exploring raw lake data before deciding what to load
  • Rarely queried history you don't want to pay to store twice
  • Data that must stay in your bucket for other tools

Watch out

  • Slower than native tables: no micro-partition stats inside files, only partition pruning
  • Read-only. No Time Travel, no DML.
  • For a hot path, add a materialized view on top or load it into a native table.
  • For a modern open-format lake with full DML, use Iceberg tables instead.
06

Loading from AWS S3 and Azure

The same four steps on every cloud: integration → trust → stage → COPY (or Snowpipe).
S3 / Blob / ADLSyour files Storage integrationIAM role / app consent External stageURL + format COPY INTO / Snowpipebatch or event-driven Tablemicro-partitions
  1. In AWS: create an IAM policy and roleThe policy allows s3:GetObject, s3:GetObjectVersion and s3:ListBucket on the bucket/prefix. Add s3:PutObject and s3:DeleteObject if you unload or use PURGE. Create a role with a placeholder trust policy for now.
  2. In Snowflake: create the storage integration (needs ACCOUNTADMIN or the CREATE INTEGRATION privilege).
  3. Copy two values back to AWSDESC INTEGRATION shows STORAGE_AWS_IAM_USER_ARN and STORAGE_AWS_EXTERNAL_ID. Put them in the role's trust policy as the Principal and the sts:ExternalId condition.
  4. Create the stage and loadTest with LIST @stage first. If that works, the trust is right.
CREATE STORAGE INTEGRATION s3_int
  TYPE = EXTERNAL_STAGE
  STORAGE_PROVIDER = 'S3'
  ENABLED = TRUE
  STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/snowflake-loader'
  STORAGE_ALLOWED_LOCATIONS = ('s3://acme-landing/orders/');

DESC INTEGRATION s3_int;   -- copy STORAGE_AWS_IAM_USER_ARN + STORAGE_AWS_EXTERNAL_ID

GRANT USAGE ON INTEGRATION s3_int TO ROLE loader_role;

CREATE FILE FORMAT ff_parquet TYPE = PARQUET;

CREATE STAGE raw.s3_orders
  URL = 's3://acme-landing/orders/'
  STORAGE_INTEGRATION = s3_int
  FILE_FORMAT = ff_parquet;

LIST @raw.s3_orders;

COPY INTO raw.orders
  FROM @raw.s3_orders
  MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE
  ON_ERROR = 'ABORT_STATEMENT';

-- Continuous loading: Snowpipe with S3 event notifications
CREATE PIPE raw.orders_pipe AUTO_INGEST = TRUE AS
  COPY INTO raw.orders FROM @raw.s3_orders
  MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE;

SHOW PIPES;  -- copy notification_channel (an SQS ARN) into the bucket's
             -- S3 event notification for "All object create events"
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "AWS": "<STORAGE_AWS_IAM_USER_ARN>" },
    "Action": "sts:AssumeRole",
    "Condition": { "StringEquals": { "sts:ExternalId": "<STORAGE_AWS_EXTERNAL_ID>" } }
  }]
}

Loading best practices

  • File size: aim for roughly 100–250 MB compressed per file. Thousands of tiny files add overhead, and one giant file can't be split across threads.
  • Load metadata: COPY remembers which files it loaded for 64 days and skips them on re-runs. FORCE = TRUE reloads them and creates duplicates.
  • Dry-run first: VALIDATION_MODE = RETURN_ERRORS checks files without loading.
  • Error policy: COPY defaults to ON_ERROR = ABORT_STATEMENT, and Snowpipe defaults to SKIP_FILE.
  • Batch vs continuous: scheduled COPY on your warehouse for nightly batches, Snowpipe (serverless, per-file) for files arriving all day, and Snowpipe Streaming for row-level streams from Kafka or apps.

Stage types, COPY options and pipe troubleshooting are covered in depth in Module 04 → Stage integrations.

07

Interview check: tables, tuning & loading