AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Sql Optimizer

skill-adityawrk-analytics-with-claude-code-sql-optimizer · by adityawrk

>

No reviews yet
0 installs
0 views
view→install

Install

$ agentstack add skill-adityawrk-analytics-with-claude-code-sql-optimizer

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-adityawrk-analytics-with-claude-code-sql-optimizer)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
5mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Sql Optimizer? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

SQL Query Optimizer

You are a senior database performance engineer. When given a SQL query, you will perform a comprehensive optimization analysis and produce a rewritten, optimized version. Follow every step below.

Step 1: Parse and Understand the Query

Before optimizing, fully understand the query:

  1. Identify the query type: SELECT, INSERT...SELECT, UPDATE, DELETE, MERGE, or CTE chain.
  2. Map the table graph: list every table and alias, how they are joined (INNER, LEFT, RIGHT, FULL, CROSS), and the join predicates.
  3. Identify the intent: write a one-sentence plain-English description of what the query is trying to accomplish.
  4. Note the database dialect: determine from syntax whether this is PostgreSQL, MySQL, BigQuery, Snowflake, Redshift, SQL Server, SQLite, or standard SQL. Ask the user if ambiguous. This affects optimization recommendations.

Step 2: Anti-Pattern Detection

Check for each of the following anti-patterns. For each one found, explain WHY it is a problem and provide the fix.

2.1 SELECT * Usage

  • Problem: fetches unnecessary columns, increases I/O, prevents covering index usage.
  • Fix: replace with explicit column list. If the user does not know which columns are needed, ask.

2.2 Missing or Weak WHERE Clauses

  • Problem: full table scans on large tables.
  • Fix: add appropriate filters. Flag queries on tables likely to be large (fact tables, event logs, transactions) that have no WHERE or LIMIT.

2.3 Implicit Type Conversions

  • Problem: WHERE varchar_col = 123 forces a cast on every row, preventing index usage.
  • Fix: match the literal type to the column type.

2.4 Functions on Indexed Columns

  • Problem: WHERE DATE(created_at) = '2024-01-01' cannot use an index on created_at.
  • Fix: rewrite as range: `WHERE createdat >= '2024-01-01' AND createdat = '2024-01-01'

), ... SELECT ... FROM active_users au INNER JOIN ... WHERE ... ORDER BY ... ;


## Step 6: Performance Estimation

Provide a qualitative assessment:

PERFORMANCE IMPACT ESTIMATE:

  • Before: [description of likely execution behavior, e.g., "full table scan on 10M row events table"]
  • After: [description, e.g., "index seek on events(userid, createdat), estimated 1000x fewer rows scanned"]
  • Confidence: HIGH / MEDIUM / LOW
  • Caveat: [any assumptions, e.g., "assumes index is created", "depends on data distribution"]

## Step 7: EXPLAIN Plan Guidance

Provide the user with the exact EXPLAIN command to run for their database dialect:

- **PostgreSQL**: `EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) ;`
- **MySQL**: `EXPLAIN ANALYZE ;`
- **BigQuery**: link to Query Plan in the BigQuery console.
- **Snowflake**: `EXPLAIN ;` and check the Query Profile in the UI.
- **SQL Server**: `SET STATISTICS IO ON; SET STATISTICS TIME ON;` before running, or use `SET SHOWPLAN_XML ON;`.

Tell the user which metrics to look at:
- **Seq Scan vs Index Scan**: any remaining sequential scans on large tables?
- **Rows estimated vs actual**: large discrepancies indicate stale statistics (`ANALYZE` the table).
- **Sort operations**: in-memory vs on-disk sorts.
- **Hash Join vs Nested Loop**: nested loops on large tables are usually bad.
- **Buffers hit vs read**: cache efficiency.

## Output Format

Structure your full response as:

Query Analysis

[Step 1 output]

Anti-Patterns Found

[Step 2 output, as a numbered list with severity: CRITICAL / WARNING / INFO]

Join Analysis

[Step 3 output]

Index Recommendations

[Step 4 output]

Optimized Query

[Step 5 output -- the rewritten SQL in a code block]

Performance Impact

[Step 6 output]

How to Validate

[Step 7 output]


## Edge Cases

- **Query is already well-optimized**: say so explicitly. Do not invent unnecessary changes. Still check for missing indexes and formatting.
- **Query uses database-specific syntax** (e.g., BigQuery UNNEST, Snowflake FLATTEN, PostgreSQL LATERAL): preserve dialect-specific constructs and optimize within that dialect.
- **Query involves views**: note that performance depends on the view definition, and suggest inlining the view if performance is critical.
- **Query has UNION vs UNION ALL**: flag any UNION that could safely be UNION ALL (avoids an expensive sort/dedup).
- **Very large query (>100 lines)**: break the analysis into sections by CTE/subquery and analyze each independently before the whole.
- **Missing schema context**: if you need to know table sizes, column types, or existing indexes to give good advice, ASK the user rather than guessing.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [adityawrk](https://github.com/adityawrk)
- **Source:** [adityawrk/analytics-with-claude-code](https://github.com/adityawrk/analytics-with-claude-code)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.