finding-expensive-queries

Find and rank expensive Snowflake queries by cost, execution time, or scanned data volume. Use cases include locating slow or problematic queries, handling requests mentioning “query history,” “top queries,” “most expensive queries,” or “slowest queries,” analyzing warehouse costs or identifying optimization candidates, and finding queries with the largest scanned data or worst overflow. Returns a ranked list of queries with metrics and optimization suggestions.

Last repository push
GitHub Stars
137
Forks
13
Issues / PRs
5

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "finding-expensive-queries" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-7469484130c2ee6b1a4dae3eff102218bcc8b0db986f3bf7ddabe1b6b19ef1e4. Verify the upstream source and version against https://github.com/AltimateAI/data-engineering-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Find and rank expensive Snowflake queries by cost, execution time, or scanned data volume. Use cases include locating slow or problematic queries, handling requests mentioning “query history,” “top queries,” “most expensive queries,” or “slowest queries,” analyzing warehouse costs or identifying optimization candidates, and finding queries with the largest scanned data or worst overflow. Returns a ranked list of queries with metrics and optimization suggestions.

0 Downloads

Introduction source: third_party · AltimateAI · 0.0.1 Reference

SkillPi interpretation

Tasks
Query history → Rank by metric → Identify patterns → Recommend optimizations**
Audience
Not specified in the source documentation.
Inputs and outputs
Not specified in the source documentation.
Software, accounts and paid services
Not specified in the source documentation.
Limits and differences
Not specified in the source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: finding-expensive-queries
description: |
  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.

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_compute queries
  • Same query_hash repeated (caching opportunity)
  • partitions_scanned = partitions_total (no pruning)
  • High gb_spilled (memory pressure)

5. Return Results

Provide:

  1. Ranked list of expensive queries with key metrics
  2. Common patterns identified
  3. Top 3-5 optimization recommendations
  4. 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

Current listing version

0.0.1

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 针对 Snowflake 查询成本与性能分析,解决企业级数据治理与优化痛点
  • 提供多维度指标(成本、时间、扫描量、溢出)的综合分析能力
Trigger Precision85/100

Highlights

  • 触发词精准完整,覆盖多种变体,边界清晰
  • description 位置正确,内容完整无截断
Structure and Standards92/100

Highlights

  • Phase/步骤清晰,有出口条件,含端到端示例
  • frontmatter完整,单文件未超限,排版规范
Execution Reliability88/100

Highlights

  • 工具来源明确(Snowflake ACCOUNT_USAGE 视图),参数正确
  • 覆盖主要异常,不可逆操作无涉及,执行流程可靠
Evidence Verifiability (mean of the first four)86/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Not specified in the source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.