Agent skill

Nw Query Optimization

by nWave-ai in nWave-ai/nWave

SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns

MITAuto-check passedDatabases

Install Nw Query Optimization

skills CLI
$ npx skills add nWave-ai/nWave --skill nw-query-optimization -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install nWave-ai/nWave nw-query-optimization --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/nWave-ai/nWave.git skills-src && mkdir -p .claude/skills && cp -r skills-src/nWave/skills/nw-query-optimization .claude/skills/nw-query-optimization && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
nw-query-optimization
GitHub stars
617
Token cost
~1.3k tokens
SKILL.md length
499 words
Files
1
Skills in repo
106
Repo updated
First seen
Licence
MIT

At a glance

SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns

  • Tasks that involve Query optimization
  • SKILL.md covers Cost-Based Optimization, Indexing Strategies, SQL Optimization Patterns and JOIN Algorithm Selection, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve NoSQL databases

What it does

Nw Query Optimization is an agent skill from nWave-ai/nWave. SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering Query optimization, NoSQL databases and SQL. It works with SQL. The repository describes itself as: AI agents that guide you from idea to working code, with you in control at every step. The licence is MIT.

When your agent uses it

  • Tasks that involve Query optimization
  • Tasks that involve NoSQL databases
  • Tasks that involve SQL

Example prompts

  • “/nw-query-optimization”

What it can do on your machine

Read from SKILL.md and the folder at commit da401a8. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql and javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Nw Query Optimization loads about 1.3k tokens when it runs. Until then it costs about 48 tokens; SKILL.md has 499 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~48
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from nWave-ai/nWave at commit da401a8, republished under its MIT licence (© nWave-ai). 499 words, ~1,333 tokens.

Download SKILL.mdSave it as .claude/skills/nw-query-optimization/SKILL.md (or your agent's skills folder).
name
nw-query-optimization
description
SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns
user-invocable
false
disable-model-invocation
true

Query Optimization

Cost-Based Optimization

Modern relational DBs use cost-based optimizers (CBO): generate plan candidates -> estimate cost via statistics (row counts, distributions, selectivity) -> select lowest I/O/CPU/memory plan. Stale statistics lead to suboptimal plans.

Execution Plan Analysis

Validate optimization with EXPLAIN before and after changes.

sql
-- PostgreSQL (add ANALYZE for actual runtime stats)
EXPLAIN ANALYZE SELECT order_id, total FROM orders WHERE customer_id = 12345;
-- MySQL: EXPLAIN FORMAT=JSON ... | SQL Server: SET STATISTICS IO ON

Key indicators: Seq Scan/Table Scan = missing index | Index Scan/Seek = efficient | Hash Join = large equality joins | Nested Loop = small/indexed inner | Merge Join = pre-sorted inputs | Sort = watch disk spills

Indexing Strategies

B-Tree (Default)

Supports: equality, range, sorting, prefix matching | O(log n) lookup | General-purpose, all major DBs default

Hash

Equality only | O(1) lookup | High-cardinality exact-match | No range/sorting/pattern support

Covering Indexes

Include all query columns in index -> eliminates table access (index-only scan) | Trade-off: larger index, slower writes

sql
-- Covering index for: SELECT name, email FROM users WHERE status = 'active'
CREATE INDEX idx_users_status_covering ON users(status) INCLUDE (name, email);
PostgreSQL Specialized
  • GiST: Geometric data, full-text search, nearest-neighbor
  • GIN: Arrays, full-text search, JSONB queries
  • BRIN: Large tables with physically correlated data (timestamps), minimal storage
  • SP-GiST: Non-balanced structures, point-based geometric queries
Compound Index Design

Order by: 1. Equality conditions first (highest selectivity) | 2. Sort columns second | 3. Range conditions last

MongoDB ESR Rule

Equality-Sort-Range ordering for compound indexes:

javascript
// Query: status = "A", qty > 20, sorted by item
// Optimal index:
db.collection.createIndex({ status: 1, item: 1, qty: 1 })
//                          E(quality)  S(ort)   R(ange)

SQL Optimization Patterns

Select Only Needed Columns
sql
-- Bad: SELECT * retrieves unnecessary data, prevents covering indexes
SELECT * FROM orders WHERE customer_id = 12345;

-- Good: Specify columns, enables covering index
SELECT order_id, order_date, total FROM orders WHERE customer_id = 12345;
Other Key Patterns
  • CTEs: Improve readability but not always performance -- PostgreSQL may materialize CTEs (pre-v12), MySQL inlines them
  • Window functions: Use SUM() OVER, RANK() OVER (PARTITION BY ...) for analytics without self-joins
  • Pagination: Prefer keyset (WHERE id > last_seen ORDER BY id LIMIT N) over OFFSET for deep pages
  • Parameterized queries: Prevent SQL injection AND enable plan caching (cursor.execute("... WHERE id = %s", (id,)))

JOIN Algorithm Selection

AlgorithmBest WhenCost
Nested LoopSmall outer table, indexed inner tableO(n * m) worst, O(n * log m) with index
Hash JoinLarge tables, equality joins, no useful indexesO(n + m) build + probe
Merge JoinBoth inputs already sorted (index order)O(n + m) after sort
Show full SKILL.md (210 more words)Show less

Cardinality Estimation

Optimizer predicts row counts using: Histograms (value distribution) | Density vectors (non-histogram columns) | Statistics objects via ANALYZE (PostgreSQL) / UPDATE STATISTICS (SQL Server)

When estimation is wrong (correlated columns, skewed data, multi-table joins): 1. Run ANALYZE/UPDATE STATISTICS | 2. Create multi-column statistics | 3. Query hints as last resort

NoSQL Query Optimization

MongoDB

Place $match/$project early in pipelines | Use $lookup sparingly (left outer joins) | Compound indexes following ESR | Validate with explain("executionStats")

Cassandra

Always include partition key | Design tables around query patterns (query-first) | Use SAI over SASI (43% throughput gain) | Avoid ALLOW FILTERING (full cluster scan) | Materialized views add write overhead

DynamoDB

Use Query not Scan | Design partition keys for even distribution | GSIs for alternative access patterns | Single-table design with composite sort keys

Redis

FT.SEARCH for complex queries (RediSearch module) | Design key naming for efficient SCAN | Use pipelining for batch ops

Anti-Patterns to Detect

  • **SELECT ***: Wastes I/O, prevents covering indexes
  • Missing indexes on WHERE/JOIN/ORDER BY columns: full table scans
  • N+1 queries: Fetch in loops instead of JOINs/batch
  • Implicit type conversions: Prevents index use (WHERE varchar_col = 123)
  • Functions on indexed columns: WHERE UPPER(name) = 'JOHN' blocks index; use function-based indexes
  • Missing pagination: Unbounded result sets
  • Hot partitions (NoSQL): Low-cardinality partition keys concentrate load
  • ALLOW FILTERING (Cassandra): Expensive full-cluster scans
  • Large partitions (Cassandra): >100MB degrades performance

© nWave-ai, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in nWave/skills/nw-query-optimization of nWave-ai/nWave.

Open the folder on GitHubat commit da401a8

Compare with similar skills

Nw Query Optimization next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Nw Query Optimization compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Nw Query Optimization this skillnWave-ai/nWave617—~1.3kAutomated safety check: PassMIT
Postgresql Best Practices CloudbaseTencentCloudBase/CloudBase-AI-Toolkit1.1k1 repos~1.3kAutomated safety check: PassMIT
Query Expertjamesrochabrun/skills216—~4.3kAutomated safety check: PassMIT
DatabasesMicrock/ordinary-claude-skills403—~1.9kAutomated safety check: NotesMIT
SQL Optimization Patternsynulihao/AgentSkillOS61711 repos~3.3kAutomated safety check: PassNone
Query Engine Designrevfactory/claude-code-harness120—~474Automated safety check: PassNone

Similar skills

  • Postgresql Best Practices Cloudbase

    TencentCloudBase/CloudBase-AI-Toolkit

    CloudBase PostgreSQL access-pattern and slow-query quality guidance.

    1.1k GitHub starsUsed in 1 repo~1.3k tokens
    DatabasesAuto-check passed
  • Query Expert

    jamesrochabrun/skills

    Master SQL and database queries across multiple systems. An agent skill from jamesrochabrun/skills.

    216 GitHub stars~4.3k tokensUpdated 8 mo ago
    DatabasesAuto-check passed
  • Databases

    Microck/ordinary-claude-skills

    Work with MongoDB (document database, BSON documents, aggregation pipelines, Atlas cloud) and PostgreSQL (relational database, SQL queries, psql CLI, pgAdmin).

    403 GitHub stars~1.9k tokensUpdated 1 mo ago
    DatabasesAuto-check: notes
  • SQL Optimization Patterns

    ynulihao/AgentSkillOS

    Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.

    617 GitHub starsUsed in 11 repos~3.3k tokens
    DatabasesAuto-check passed
  • Query Engine Design

    revfactory/claude-code-harness

    SQL query engine design and implementation guide. An agent skill from revfactory/claude-code-harness.

    120 GitHub stars~474 tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • SQL Optimization Patterns

    sickn33/agentic-awesome-skills

    Diagnose slow SQL with query plans, preserve query results, and verify indexing or query changes against representative data.

    47k GitHub starsUsed in 1 repo~566 tokens
    DatabasesAuto-check passed

More from nWave-ai/nWave

All 106 skills in this repo
  • DELIVER wave orchestration workflow -- 9 phases from baseline to finalization.

    617 GitHub stars~974 tokensUpdated 22 days ago
    Auto-check passed
  • Nw Diagram

    nWave-ai/nWave

    Generates C4 architecture diagrams (context, container, component) in Mermaid or PlantUML.

    617 GitHub stars~640 tokensUpdated 22 days ago
    Auto-check passed
  • Nw Diverge

    nWave-ai/nWave

    Generates 3-5 divergent design directions through JTBD analysis, competitive research, structured brainstorming, and taste evaluation before convergence.

    617 GitHub stars~2.2k tokensUpdated 22 days ago
    Auto-check passed
  • Nw Document

    nWave-ai/nWave

    Creates evidence-based documentation following DIVIO/Diataxis principles.

    617 GitHub stars~1.4k tokensUpdated 22 days ago
    Auto-check passed
  • Nw Execute

    nWave-ai/nWave

    A skill your agent uses when a DELIVER roadmap already exists and you need to dispatch exactly one identified step through its TDD cycle.

    617 GitHub stars~3k tokensUpdated 22 days ago
    Auto-check passed
  • Nw Refactor

    nWave-ai/nWave

    Applies the Refactoring Priority Premise (RPP) levels L1-L6 for systematic code refactoring.

    617 GitHub stars~1.2k tokensUpdated 22 days ago
    Auto-check passed

Works with

Categories

Questions about Nw Query Optimization

What does Nw Query Optimization do?

SQL and NoSQL query optimization techniques, indexing strategies, execution plan analysis, JOIN algorithms, cardinality estimation, and database-specific query patterns. Nw Query Optimization is an agent skill from nWave-ai/nWave.

When should I use Nw Query Optimization?

Nw Query Optimization fits situations like: tasks that involve Query optimization; tasks that involve NoSQL databases; tasks that involve SQL.

How do I install Nw Query Optimization in Claude Code?

Run `npx skills add nWave-ai/nWave --skill nw-query-optimization -a claude-code`. Or copy the skill folder (nWave/skills/nw-query-optimization in nWave-ai/nWave) into .claude/skills/nw-query-optimization in your project. Claude Code loads it when a task matches its description.

How do I install Nw Query Optimization in Codex?

Run `npx skills add nWave-ai/nWave --skill nw-query-optimization -a codex`. Or copy the skill folder (nWave/skills/nw-query-optimization in nWave-ai/nWave) into .agents/skills/nw-query-optimization in your project. Codex loads it when a task matches its description.

Can I use Nw Query Optimization in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add nWave-ai/nWave --skill nw-query-optimization -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/nw-query-optimization, .gemini/skills/nw-query-optimization, .github/skills/nw-query-optimization and .opencode/skills/nw-query-optimization in your project.

What does Nw Query Optimization need to run?

SKILL.md names no scripts, command-line tools or credentials: Nw Query Optimization is instructions for the agent only.

Does Nw Query Optimization access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Nw Query Optimization safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Nw Query Optimization use?

Nw Query Optimization is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Nw Query Optimization use?

About 1.3k tokens (SKILL.md is roughly 5.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Nw Query Optimization?

Skills that share tags, products or a category with Nw Query Optimization: Postgresql Best Practices Cloudbase (TencentCloudBase/CloudBase-AI-Toolkit, 1.1k stars), Query Expert (jamesrochabrun/skills, 216 stars), Databases (Microck/ordinary-claude-skills, 403 stars) and SQL Optimization Patterns (ynulihao/AgentSkillOS, 617 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Nw Query Optimization?

nWave-ai (a GitHub organization) maintains it in nWave-ai/nWave, which has 617 GitHub stars. The repository holds 106 skills in this directory. The repository was last updated on September 16, 2026.

Source: nWave-ai/nWave on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.