sql-optimization

sql-optimization is a skill for Claude Code, Codex from sawrus/agent-guides. It costs 0 tokens per session (333 once invoked), scanned A, original, MIT.

A set of practices for making SQL queries, which retrieve data from databases, run more efficiently. It includes query-writing patterns, window functions, and guidance for Snowflake databases.

In plain words
What is it for?
Use it when writing complex SQL, reviewing query performance, choosing columns and filters, using window functions, or designing indexes and Snowflake clustering.
Why use it?
It helps reduce slow queries and avoid patterns that prevent indexes or table partitions from being used effectively.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when writing complex SQL, reviewing query performance, choosing columns and filters, using window functions, or designing indexes and Snowflake clustering.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/sawrus/agent-guides/sql-optimization
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add sawrus/agent-guides --skill sql-optimization
Clone the repo
git clone --depth 1 https://github.com/sawrus/agent-guides

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for sql-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/sawrus/agent-guides/sql-optimization/github.svg)](https://agentmods.dev/skills/sawrus/agent-guides/sql-optimization)
Your own site
<a href="https://agentmods.dev/skills/sawrus/agent-guides/sql-optimization"><img src="https://agentmods.dev/badge/skills/sawrus/agent-guides/sql-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for sql-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/sawrus/agent-guides/sql-optimization"><img src="https://agentmods.dev/badge/skills/sawrus/agent-guides/sql-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 333 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00333
Opus 5.5 $0.00000 $0.00133
Sonnet 5.5 $0.00000 $0.00067
Haiku 4.5 $0.00000 $0.00033

Measured 1mo ago against content hash 5e1b97dd8255, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

sql-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

areas/software/data-engineering/skills/sql-optimization/SKILL.md · 48 lines

What it actually says

Skill: SQL Optimization

When to load

When writing complex queries, optimizing slow queries, designing indexes, or reviewing query performance.

Core Patterns

-- ✅ Column projection — never SELECT *
SELECT user_id, created_at, total_amount FROM orders WHERE created_at >= '2026-01-01';

-- ✅ Partition pruning — filter on partition column first
SELECT user_id, total_amount
FROM orders
WHERE order_date = '2026-01-15'  -- partition filter first
  AND status = 'completed';

-- ❌ Function on indexed column defeats index
WHERE DATE(created_at) = '2026-01-15'
-- ✅ Range comparison preserves index
WHERE created_at >= '2026-01-15' AND created_at < '2026-01-16'

Window Functions (prefer over self-joins)

SELECT
    user_id, order_date, amount,
    SUM(amount) OVER (
        PARTITION BY user_id ORDER BY order_date
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) AS cumulative_amount,
    ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY order_date DESC) AS recency_rank
FROM orders;

Snowflake-Specific

-- Cluster keys on large tables (> 1 TB)
ALTER TABLE orders CLUSTER BY (order_date, status);

-- COPY INTO for bulk loads — never row-by-row INSERT
COPY INTO orders FROM @my_stage/orders/
FILE_FORMAT = (TYPE = PARQUET) MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE;
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 48 lines · 0 tokens per session scan A 5e1b97dd8255

Subscribe to this mod's changes

sql-optimization is a skill published in the GitHub repository sawrus/agent-guides (19 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 333 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

deprecation-and-migration

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset…

addyosmani/agent-skills · 69 tokens

airtable-automation

Automate Airtable tasks via Rube MCP (Composio): records, bases, tables, fields, views. Always search tools first for current schemas.

sickn33/agentic-awesome-skills · 37 tokens

dbt

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills · 45 tokens

event-sourcing

Expert Event Sourcing assistance covering immutable append-only event logs, state reconstruction, snapshotting, event versioning, and temporal queries. Use when building audit-compliant persistence systems, financial ledgers, or historical state tracking.

G1Joshi/Agent-Skills · 48 tokens

cassandra

Expert Apache Cassandra assistance covering CQL, partition keys, clustering columns, tombstone avoidance, and nodetool. Use when designing linear scale data stores, high-write ingestion engines, or tuning consistency levels.

G1Joshi/Agent-Skills · 44 tokens

clickhouse

Expert ClickHouse columnar database assistance covering MergeTree engines, materialized views, vector search, and real-time ingestion. Use when querying analytical telemetry, logs, time-series data, or building analytics APIs.

G1Joshi/Agent-Skills · 44 tokens