finding-expensive-queries

Solid

Finds and ranks expensive Snowflake queries by cost, time, or data scanned. Use when: (1) User asks to find slow, expensive, or problematic queries (2) Task mentions "query history", "top queries", "most expensive", or "slowest queries" (3) Analyzing warehouse costs or identifying optimization candidates (4) Finding queries that scan the most data or have the most spillage Returns ranked list of queries with metrics and optimization recommendations.

Data & Documents 113 stars 8 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 85/100

Stars 20%
68
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Finding Expensive Queries **Query history → Rank by metric → Identify patterns → Recommend optimizations** ## Workflow ### 1. Ask What to Optimize For Before querying, clarify: - Time period? (last day, week, month) - Metric? (execution time, bytes scanned, cost, spillage) - Warehouse? (specific or all) - User? (specific or all) ### 2. Find Expensive Queries by Cost Use QUERY_ATTRIBUTION_HISTORY for credit/cost analysis: ```sql SELECT query_id, warehouse_name, user_name, credits_attributed_compute, start_time, end_time, query_tag FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY WHERE start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP()) ORDER BY credits_attributed_compute DESC LIMIT 20; ``` ### 3. Get Performance Stats for Specific Queries Use QUERY_HISTORY for detailed performance metrics (run separately, not joined): ```sql SELECT query_id, query_text, total_elapsed_time/1000 as seconds, bytes_scanned/1e9 as gb_scanned, bytes_spilled_to_local_storage/1e9 as gb_spilled_local, bytes_spilled_to_remote_storage/1e9 as gb_spilled_remote, partitions_scanned, partitions_total FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE query_id IN ('<query_id_1>', '<query_id_2>', ...) AND start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP()); ``` ### 4. Identify Patterns Look for: - High `credits_attributed_compute` queries - Same `query_hash` repeated (caching opportunity) - `partitions_scanned = partitions_to...

Details

Author
AltimateAI
Repository
AltimateAI/data-engineering-skills
Created
6 months ago
Last Updated
1 weeks ago
Language
N/A
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

Data & Documents Listed

cost-optimization-data

Query cost analysis, partition pruning, slot reservation strategies, storage tiering, and cloud data warehouse cost reduction. Use this skill whenever the cloud data bill is unexpectedly high, a specific query is scanning too much data, the team wants to understand what's driving BigQuery/Snowflake/Redshift costs, or when choosing between on-demand vs. reserved capacity. Also trigger when the user mentions bytes scanned, slot utilization, query cost, storage costs, Redshift concurrency, Snowflake credits, or when trying to set up cost alerts and budgets. If someone says "our BigQuery bill jumped" or "this query is expensive", this skill should be active immediately.

1 Updated 1 weeks ago
Methasit-Pun
Data & Documents Solid

optimizing-query-by-id

Optimizes Snowflake query performance using query ID from history. Use when optimizing Snowflake queries for: (1) User provides a Snowflake query_id (UUID format) to analyze or optimize (2) Task mentions "slow query", "optimize", "query history", or "query profile" with a query ID (3) Analyzing query performance metrics - bytes scanned, spillage, partition pruning (4) User references a previously run query that needs optimization Fetches query profile, identifies bottlenecks, returns optimized SQL with expected improvements.

113 Updated 1 weeks ago
AltimateAI
API & Backend Solid

database-performance

Use when a database is the bottleneck. Covers finding the expensive queries, index strategy, lock contention, connection saturation, and the schema decisions that make queries fast or impossible.

23 Updated today
nimadorostkar