Snowflake development

From borghei/Claude-Skills · View interactive version

Snowflake development is an AI agent skill from the GitHub repository borghei/Claude-Skills. Review Snowflake SQL for pruning and join problems, size warehouses and cut credit spend. Use when a Snowflake query is slow or expensive, or when sizing or reviewing warehouses.

How to use this skill

Skill file

Snowflake Development

Category: Engineering

Domain: Data Warehouse

Overview

The Snowflake Development skill provides tools for analyzing and optimizing Snowflake SQL queries, recommending warehouse sizing, and enforcing Snowflake-specific best practices. Helps data engineers reduce costs and improve query performance.

When to Use

For other databases use sql-database-assistant; for pipeline orchestration use senior-data-engineer.

Clarify First

Before analyzing or sizing, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.

Quick Start

# Analyze a Snowflake SQL file for optimization opportunities (bundled sample: 4 issues)
python scripts/snowflake_query_helper.py --file assets/sample_queries.sql --action analyze

# Get warehouse sizing recommendations, costed at your hours and contract credit price
python scripts/snowflake_query_helper.py --action warehouse-sizing --workload "etl" --data-volume "500GB" --hours 4 --credit-price 3

# Optimize a specific query
python scripts/snowflake_query_helper.py --file slow_query.sql --action optimize

Tools Overview

| Tool | Purpose | Key Flags |

|------|---------|-----------|

| snowflake_query_helper.py | Analyze, optimize Snowflake SQL and recommend warehouse sizes | --file/--sql, --action analyze/optimize/warehouse-sizing, --workload, --data-volume, --hours, --credit-price, --format human/json |

Exit codes: 0 ok (analysis found no critical issue); 1 a critical issue was found;

2 bad input (missing file, no SQL given).

Workflows

Query Performance Optimization

  1. Collect the expensive queries with real numbers (needs access to the SNOWFLAKE.ACCOUNT_USAGE share; it lags by up to about 45 minutes):

```sql

SELECT query_id, warehouse_name, total_elapsed_time / 1000 AS seconds,

bytes_scanned, partitions_scanned, partitions_total, query_text

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 20;

```

  1. Run the analyzer on those query texts for pattern-level fixes (SELECT *, functions on filter columns, always-true joins).
  2. For each query, open the Query Profile: the real evidence is partitions scanned vs total, spilling to local/remote storage, and the most expensive operator. Prefer it over the script whenever they disagree.
  3. Apply the change and verify against the same metrics before/after; done when elapsed time or bytes scanned fell on the same input.

Warehouse Right-Sizing

  1. Identify workload type (ETL, BI, ad-hoc, etc.)
  2. Run warehouse-sizing with data volume
  3. Review recommendations
  4. Implement multi-cluster settings if applicable

Scope & Limitations

In Scope:

Out of Scope:

Important Caveats:

Reference Documentation

Common Patterns

Cost Reduction

Anti-Patterns

Sizing Up to Fix a Slow Query

Mistake: Moving a slow query to a larger warehouse without reading its profile.

Why it happens: It is one setting and often helps a little.

Instead: Check the Query Profile first. Poor pruning or a bad join is not fixed by more compute; spilling to remote storage is the case where a larger size usually pays for itself.

Clustering Every Large Table

Mistake: Adding clustering keys as routine "partitioning".

Why it happens: Other warehouses need explicit partitioning.

Instead: Snowflake micro-partitions automatically. Cluster only when a frequent filter on a very large table scans most partitions, and watch the reclustering credits.

Warehouses That Never Sleep

Mistake: Leaving AUTO_SUSPEND at hours or disabled on ad-hoc and BI warehouses.

Why it happens: Users dislike the resume delay.

Instead: Suspend after 60-300 seconds; resume takes seconds while idle compute bills every second it runs.

Files

| File | Purpose |

|------|---------|

| scripts/snowflake_query_helper.py | SQL pattern analysis and warehouse sizing |

| assets/sample_queries.sql | Two queries with deliberate problems |

| references/snowflake-best-practices.md | Query, warehouse, cost and modelling practices |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.