Goal: Identify and reduce unnecessary Snowflake credit usage through query optimization, warehouse tuning, and cost monitoring.
In real-world Snowflake environments, inefficient queries and poorly configured warehouses can lead to massive credit wastage. This project demonstrates:
- How to identify inefficient queries
- How to optimize SQL and warehouse settings
- How to monitor cost using ACCOUNT_USAGE views
- How to prevent future cost overruns using Resource Monitors
| Metric | Before Optimization | After Optimization |
|---|---|---|
| Query Execution Time | ~8 seconds | ~0.8 seconds |
| Data Scanned | 100% (full scan) | ~15% (pruned) |
| Credits Used | High | ~30% Reduced |
| Auto-Suspend | 5 minutes | 60 seconds |
| Warehouse Size | SMALL | X-SMALL |
snowflake-cost-optimization/
│
├── README.md
│
├── sql/
│ ├── 01_setup.sql ← Database, warehouse setup
│ ├── 02_create_data.sql ← Create tables + bulk data
│ ├── 03_inefficient_queries.sql ← Problem queries (before)
│ ├── 04_monitor_usage.sql ← Query history + usage check
│ ├── 05_optimized_queries.sql ← Optimized queries (after)
│ ├── 06_warehouse_tuning.sql ← Warehouse optimization
│ ├── 07_resource_monitor.sql ← Cost control setup
│ └── 08_cost_dashboard.sql ← Daily usage monitoring
│
└── docs/
└── optimization_notes.md ← Key learnings
Run sql/01_setup.sql
Run sql/02_create_data.sql — inserts 10,000+ rows
Run sql/03_inefficient_queries.sql — observe high scan + slow execution
Run sql/04_monitor_usage.sql — check ACCOUNT_USAGE
Run sql/05_optimized_queries.sql — compare execution time + bytes scanned
Run sql/06_warehouse_tuning.sql — right-size warehouse + auto-suspend
Run sql/07_resource_monitor.sql — prevent future cost overruns
Run sql/08_cost_dashboard.sql — daily/weekly trend monitoring
- Added WHERE filters → Partition pruning → Less data scanned
- Reduced warehouse size → SMALL → X-SMALL → 50% credit reduction
- Auto-suspend reduced → 5 min → 60 sec → Zero idle cost
- Clustering key added → Better pruning on large table
- SELECT * replaced → Only required columns fetched
- Resource Monitor → Hard limit on credits → No surprises
Ramkumar G
- LinkedIn: linkedin.com/in/ramdba
- GitHub: github.com/Ramkumar-g-dba
- Portfolio: ramkumar-g-dba.github.io/ramkumar-portfolio