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.
Table types: pick the right one first
| Type | Time Travel | Fail-safe | Lives until | Use it for |
|---|---|---|---|---|
| Permanent (default) | 0–90 days | 7 days | Dropped | Production data you can't easily rebuild |
TRANSIENT | 0–1 day | None | Dropped | Staging, intermediate ELT tables, anything re-creatable. Saves Fail-safe storage. |
TEMPORARY | 0–1 day | None | End of session | Scratch work inside one session or procedure |
| External | None | None | Dropped (files stay) | Querying files in your lake without loading them |
| Dynamic | Yes | Yes | Dropped | Declarative pipelines that refresh to a target lag (Module 04) |
| Iceberg | Yes (Snowflake-managed) | No | Dropped | Open-format tables in your own bucket that other engines can read |
| Hybrid | Limited | — | Dropped | Row-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.
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.
- 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.
- 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 ofevent_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.
Indexes? Partitions? What Snowflake has instead
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.
| Need | Snowflake feature | Notes |
|---|---|---|
| Range filters on a big table (dates, IDs) | Clustering key | Improves pruning. Serverless reclustering cost. |
Needle-in-haystack lookups (WHERE email = ?), substring and LIKE, VARIANT fields, geo | Search Optimization Service | Builds a persistent search access path. Enterprise+. Storage plus serverless maintenance cost. |
| The same expensive aggregate queried repeatedly | Materialized view | Single-table, auto-maintained. Enterprise+. |
| Multi-table transforms kept fresh | Dynamic table | Joins allowed, refreshed to a target lag. |
| Occasional huge scans that slow everyone down | Query Acceleration Service | Offloads parts of eligible scans to serverless compute. |
| Real indexes, enforced primary keys, fast single-row reads and writes | Hybrid tables | Row store with primary key and secondary indexes. Built for operational workloads. |
| Partitioning files in a data lake | External tables / Iceberg | Partition 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.
Performance tuning: a repeatable checklist
Always start from the Query Profile (Snowsight → Query History → the query → Query Profile).| Symptom in Query Profile | Likely cause | Fix |
|---|---|---|
| Partitions scanned ≈ partitions total | Filter can't prune: wrong column, function on column, or poor clustering | Filter on the raw column (ts >= '2026-01-01', not YEAR(ts) = 2026). Add a clustering key or Search Optimization. |
| Bytes spilled to local / remote storage | Joins, sorts or aggregations don't fit in memory | Scale up the warehouse, reduce rows and columns earlier, or split the query. |
| Join output rows » input rows ("exploding join") | Missing or duplicate join keys | Fix the join condition and deduplicate dimension rows. |
| Long queued time, short execution | Warehouse saturated by concurrency | Multi-cluster (scale out) or separate warehouses per workload. |
| Long compilation time | Huge SQL, many views, or thousands of tiny micro-partitions | Simplify the SQL and compact tiny files and partitions. |
| TableScan dominates with good pruning | Selecting too many columns | Avoid SELECT *. It is a column store. |
| A few huge scans slow a shared warehouse | Outlier queries | Enable Query Acceleration, or route them to their own warehouse. |
Big ORDER BY at the end | Global sort of millions of rows | Sort 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;
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.
Loading from AWS S3 and Azure
The same four steps on every cloud: integration → trust → stage → COPY (or Snowpipe).- In AWS: create an IAM policy and roleThe policy allows
s3:GetObject,s3:GetObjectVersionands3:ListBucketon the bucket/prefix. Adds3:PutObjectands3:DeleteObjectif you unload or usePURGE. Create a role with a placeholder trust policy for now. - In Snowflake: create the storage integration (needs
ACCOUNTADMINor theCREATE INTEGRATIONprivilege). - Copy two values back to AWS
DESC INTEGRATIONshowsSTORAGE_AWS_IAM_USER_ARNandSTORAGE_AWS_EXTERNAL_ID. Put them in the role's trust policy as the Principal and thests:ExternalIdcondition. - Create the stage and loadTest with
LIST @stagefirst. 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>" } }
}]
}
- In Snowflake: create the storage integrationGive it your Azure tenant ID and the allowed container paths.
- Grant consent
DESC INTEGRATIONreturnsAZURE_CONSENT_URLandAZURE_MULTI_TENANT_APP_NAME. Open the URL as an Azure admin and accept. This registers Snowflake's service principal in your tenant. - Grant the app access to the storage accountIn the storage account (or container) open Access control (IAM) and assign Storage Blob Data Reader to the Snowflake app, or Storage Blob Data Contributor if you unload or purge. Role assignment can take a few minutes to apply.
- Create the stage and loadUse the
azure://<account>.blob.core.windows.net/<container>/<path>form, including for ADLS Gen2 accounts.
CREATE STORAGE INTEGRATION azure_int
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = 'AZURE'
ENABLED = TRUE
AZURE_TENANT_ID = '00000000-1111-2222-3333-444444444444'
STORAGE_ALLOWED_LOCATIONS = ('azure://acmelanding.blob.core.windows.net/orders/');
DESC INTEGRATION azure_int; -- open AZURE_CONSENT_URL, then grant IAM role in Azure
CREATE STAGE raw.az_orders
URL = 'azure://acmelanding.blob.core.windows.net/orders/'
STORAGE_INTEGRATION = azure_int
FILE_FORMAT = (TYPE = CSV SKIP_HEADER = 1 FIELD_OPTIONALLY_ENCLOSED_BY = '"');
LIST @raw.az_orders;
COPY INTO raw.orders FROM @raw.az_orders ON_ERROR = 'CONTINUE';
-- Continuous loading: Event Grid -> Storage Queue -> Snowpipe
CREATE NOTIFICATION INTEGRATION az_orders_queue
ENABLED = TRUE
TYPE = QUEUE
NOTIFICATION_PROVIDER = AZURE_STORAGE_QUEUE
AZURE_STORAGE_QUEUE_PRIMARY_URI = 'https://acmelanding.queue.core.windows.net/snowpipe-orders'
AZURE_TENANT_ID = '00000000-1111-2222-3333-444444444444';
-- DESC it, open its consent URL, grant "Storage Queue Data Contributor" on the queue
CREATE PIPE raw.az_orders_pipe
AUTO_INGEST = TRUE
INTEGRATION = 'AZ_ORDERS_QUEUE'
AS COPY INTO raw.orders FROM @raw.az_orders;
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:
COPYremembers which files it loaded for 64 days and skips them on re-runs.FORCE = TRUEreloads them and creates duplicates. - Dry-run first:
VALIDATION_MODE = RETURN_ERRORSchecks files without loading. - Error policy:
COPYdefaults toON_ERROR = ABORT_STATEMENT, and Snowpipe defaults toSKIP_FILE. - Batch vs continuous: scheduled
COPYon 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.