Agent skill · Audited from source
Optimizing Sql Queries
skill · jeremylongshore/claude-code-plugins-plus-skillsMIT licenceAudited 8 Oct 2026 · source 4f83675ca38a
Is it safe? Yes — SAFE, grade B (89/100). We read this skill's source at commit 4f83675ca38a and found no filesystem, network or shell access and no hard-coded secrets. What it does: Execute use when you need to work with query optimization.
Cite
Cite this page
ModelsAtlas. “Optimizing Sql Queries (jeremylongshore/claude-code-plugins-plus-skills)”. Retrieved 8 Oct 2026. https://modelsatlas.com/skills/jeremylongshore/optimizing-sql-queries
Trust audit
Audit 0.4.1 · source read 8 Oct 2026
SAFE means nothing in the source contradicts what the skill says it does. Grade B is shared by 17,406 of 18,389 audited skills.
What the source does
- FilesystemNone observedNo reads or writes in the source
- NetworkNone observedNo outbound calls in the source
- ShellNone observedNo commands run in the source
- DependenciesPinnedNothing floats
- SecretsNone foundNo keys in source
Five audit layers
| Layer | What we check | Result | Findings |
|---|---|---|---|
L0 Provenance | Repo owner, licence, archive status, activity | PASS | 0 |
L1 Static source | Secrets, path traversal, supply chain, hidden code | PASS | 0 |
L2 Instructions | Prompt injection, authority framing, hidden directives | PASS | 0 |
L3 Inventory | The files and declarations match the source | PASS | 0 |
L4 Sandbox | Run in isolation and watch behaviour | SKIPPED why | 0 |
Gates applied: no behavioural pass.
Findings (0)
No findings at any severity. We re-audit when the source changes.
Audit 0.4.1 · source sha 4f83675ca38a · 8 Oct 2026Report an issue or request a re-scan
Provenance
Who published it, and what the verdict is pinned to
- Publisherjeremylongshore GitHub userOwner of the repository this skill is read from
- Source folderjeremylongshore/claude-code-plugins-plus-skills/plugins/database/sql-query-optimizer/skills/optimizing-sql-queriesThe exact folder we audited
- LicenceMITAs the repository states it
- Commit pinned for this verdict4f83675ca38aA new audit runs when the source changes
- Repository statusNot archivedPushed today
- Sandboxed runNot runSkills are read, not executed; layer L4 is skipped
What it tells the agent
Full source on GitHub ↗Its description: Execute use when you need to work with query optimization.
--- name: optimizing-sql-queries description: 'Execute use when you need to work with query optimization. This skill provides query performance analysis with comprehensive guidance and automation. Trigger with phrases like "optimize queries", "analyze performance", or "improve query speed". ' allowed-tools: Read, Write, Edit, Grep, Glob, Bash(psql:*), Bash(mysql:*), Bash(mongosh:*) version: 1.27.0 author: Jeremy Longshore <[email protected]> license: MIT tags: - database - performance - optimizing-sql compatibility: Designed for Claude Code --- # SQL Query Optimizer ## Overview Rewrite SQL queries for maximum performance by eliminating anti-patterns, restructuring JOINs, leveraging window functions, and applying database-specific optimizations for PostgreSQL and MySQL. This skill takes a slow query and its execution plan as input and produces an optimized version with measurable improvement, along with any supporting index changes needed. ## Prerequisites - The slow SQL query text and its current execution time - `EXPLAIN ANALYZE` output (PostgreSQL) or `EXPLAIN FORMAT=JSON` output (MySQL) for the query - Table row counts and approximate data distribution for involved tables - `psql` or `mysql` CLI for testing rewrites - Knowledge of the application's acceptable result ordering and NULL handling requirements ## Instructions 1. Examine the original query structure and identify common anti-patterns: - `SELECT *` instead of specific columns (forces unnecessary I/O) - `WHERE column IN (SELECT ...)` that can be rewritten as `JOIN` or `EXISTS` - `DISTINCT` used to mask duplicate rows from incorrect JOINs - Functions applied to indexed columns in WHERE clauses (`WHERE UPPER(name) = 'FOO'`) - `OR` conditions that prevent index usage - `NOT IN` with nullable columns (produces wrong results and poor plans) 2. Analyze the execution plan to identify the most expensive operation nodes. Focus optimization effort on the node consuming the most time or processing the most rows. 3. Rewrite subqueries as JOINs where possible. Convert correlated subqueries to lateral joins (PostgreSQL) or derived tables. Replace `IN (SELECT ...)` with `EXISTS (SELECT 1 ...)` for existence checks since EXISTS short-circuits after the first match. 4. Optimize JOIN ordering for the query planner: place the most selective table (fewest matching rows after WHERE filters) as the driving table. Use `JOIN` hints only as a last resort since the optimizer usually picks the correct order with accurate statistics. 5. Replace multiple OR conditions on the same column with `IN (...)`: change `WHERE status = 'active' OR status = 'pending'` to `WHERE status IN ('active', 'pending')`. For OR across different columns, consider UNION ALL of two simpler queries. 6. Apply window functions to replace self-joins or correlated subqueries. Use `ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)` for top-N-per-group queries instead of `GROUP BY` with subqueries. 7. Leverage CTEs (Common Table Expressions) for readability but be aware that PostgreSQL versions before 12 materialize all CTEs. For performance-critical queries on older PostgreSQL, inline the CTE as a subquery. 8. Optimize aggregation queries by filtering before grouping (`WHERE` is more efficient than `HAVING` for non-aggregate conditions), using partial indexes for filtered aggregates, and considering materialized views for expensive recurring aggregations. 9. Test the rewritten query with `EXPLAIN ANALYZE` and compare execution time, row estimates vs. actuals, and buffer usage against the original. The optimized version should show fewer rows processed, index scans replacing sequential scans, and lower total execution time. 10. Document each change made, the reason for the change, and the measured impact so the development team understands and can apply similar patterns to future queries. ## Output - **Optimized SQL query** with comments explaining each structural change - **Before/after execution plans** showing performance improvement - **Index recommendations** (CREATE INDEX statements) needed to support the optimized query - **Anti-pattern report** listing issues found in the original query with explanations - **Performance metrics comparison** (execution time, rows scanned, buffer hits) ## Error Handling | Error | Cause | Solution | |-------|-------|---------| | Rewritten query returns different results | JOIN type change (INNER vs LEFT) or NULL handling difference | Verify result sets match with `EXCEPT` query; preserve original JOIN types; handle NULLs explicitly with `COALESCE` | | Optimized query slower than original | Statistics outdated causing planner to choose wrong plan | Run `ANALYZE` on involved tables; compare `estimated rows` vs `actual rows` in EXPLAIN; consider `SET enable_seqscan = off` to test alternative plans | | CTE materialization hurting performance | PostgreSQL <12 materializes CTEs preventing predicate pushdown | Inline the CTE as a subquery; upgrade PostgreSQL; add `AS NOT MATERIALIZED` hint in PostgreSQL 12+ | | Window function query uses excessive memory | Large partition sizes with ORDER BY in window specification | Add `LIMIT` to outer query; use index matching the PARTITION BY and ORDER BY columns; increase `work_mem` for the session | | UNION ALL produces duplicates | Overlapping conditions in constituent queries | Add mutually exclusive WHERE conditions to each branch; or use UNION (with dedup cost) if overlap is unavoidable | ## Examples **Converting correlated subquery to JOIN**: Original: `SELECT * FROM orders WHERE customer_id IN (SELECT id FROM customers WHERE region = 'US')` taking 8 seconds with sequential scan on orders. Rewrite: `SELECT o.* FROM orders o JOIN customers c ON o.customer_id = c.id WHERE c.region = 'US'` using index on `orders.customer_id` reduces to 120ms. **Top-N per group with window function**: Original uses self-join to find the 3 most recent orders per customer (
Excerpt, first 6,000 characters of SKILL.md, verbatim from the audited commit. It is text from someone else’s repository, quoted so you can judge it before your agent reads it.
Install
Pinned to the audited commit 4f83675
git clone https://github.com/jeremylongshore/claude-code-plugins-plus-skills git -C claude-code-plugins-plus-skills checkout 4f83675ca38a
The author documents no install command, so this uses the repository directly. Our verdict covers commit 4f83675ca38a only.
Works in which agents?
What its own text says, not a test
| Agent | Status | More |
|---|---|---|
| Claude Code | Mentioned in its text, not tested | Skills for Claude Code · About Claude Code |
Audit history
Every audit, every source change
- ✓SAFE B 89 / 100
first audit · source
4f83675ca38a
README badge
For maintainers · shows the latest audit
[](https://modelsatlas.com/skills/jeremylongshore/optimizing-sql-queries/)
The badge shows our verdict and grade for this skill, and links back to this page. It changes when the audit does.
Similar skills
All data & analysis skills →jeremylongshore/claude-code-plugins-plus
Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com.
jeremylongshore/claude-code-plugins-plus
Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com.
jeremylongshore/claude-code-plugins-plus
Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com.
jeremylongshore/claude-code-plugins-plus
Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com.
jeremylongshore/claude-code-plugins-plus
Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com.
jeremylongshore/claude-code-plugins-plus
Deploy and orchestrate Vertex AI ADK agents using A2A protocol. Manages
Add this badge to your README
[](https://modelsatlas.com/skills/jeremylongshore/optimizing-sql-queries/)
<a href="https://modelsatlas.com/skills/jeremylongshore/optimizing-sql-queries/"><img src="https://modelsatlas.com/skills/jeremylongshore/optimizing-sql-queries/badge.svg" alt="ModelsAtlas: SAFE B"></a>
Questions about Optimizing Sql Queries
What does the Optimizing Sql Queries skill do?
Is Optimizing Sql Queries safe to install?
What can Optimizing Sql Queries access on my machine?
Which assistants does Optimizing Sql Queries work with?
How current is this page?
Sources
- github.com/jeremylongshore/claude-code-plugins-plus-skills/tree/ — the audited source at commit 4f83675ca38a and every finding aboveObserved · 8 Oct 2026
Spotted something wrong? Report a correction · Methodology
Keep going in your AI
Opens with this page as the source. We add nothing else to the prompt.
- What does the Optimizing Sql Queries skill do?
- Is Optimizing Sql Queries safe to install?
- What can Optimizing Sql Queries access on my machine?