finding-expensive-queries
@altimateai · 收录于 1 周前
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.
适合你,如果你经常需要分析 Snowflake 查询性能并降低计算成本
/ 下载安装
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code
~/.claude/skills/(项目级 .claude/skills/)Codex CLI
~/.codex/skills/Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add altimateai/data-engineering-skills/finding-expensive-queries/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- altimateai/data-engineering-skills/finding-expensive-queries/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify altimateai/data-engineering-skills/finding-expensive-queries安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
109GitHub stars
~472上下文体积 · 单文件
镜像托管
怎么用
技能原文 SKILL.md
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:
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):
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_computequeries - Same
query_hashrepeated (caching opportunity) partitions_scanned = partitions_total(no pruning)- High
gb_spilled(memory pressure)
5. Return Results
Provide:
- Ranked list of expensive queries with key metrics
- Common patterns identified
- Top 3-5 optimization recommendations
- Specific queries to investigate further
Common Filters
-- Time range (required)
WHERE start_time >= DATEADD('days', -7, CURRENT_TIMESTAMP())
-- By warehouse
AND warehouse_name = 'ANALYTICS_WH'
-- By user
AND user_name = 'ETL_USER'
-- Only queries over cost threshold
AND credits_attributed_compute > 0.01
-- Only queries over time threshold
AND total_elapsed_time > 60000 -- over 1 minute按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →
评论
登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。
…