Skip to content
Back to skills

Sql Optimization

ASecurity

Applies SQL optimization patterns, window functions, and Snowflake-specific tuning; use when writing complex queries, optimizing slow queries, designing indexes, or reviewing query performance.

  • 19 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 19, 2026
ai-agentssqlperformance

Security analysis

A100/100

Scanned October 19, 2026

npx -y skills add sawrus/agent-guides --skill sql-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sql Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sawrus-sql-optimization/badge)](https://www.skillsdirectory.com/skills/sawrus-sql-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sql-optimization
description: "Applies SQL optimization patterns, window functions, and Snowflake-specific tuning; use when writing complex queries, optimizing slow queries, designing indexes, or reviewing query performance."
---

# Skill: SQL Optimization

## When to load

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

## Core Patterns

```sql
-- ✅ 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)

```sql
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

```sql
-- 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;
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.