db-query-patterns

Detect inefficient SQL query patterns and suggest performance optimizations.

18|4|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/Hainrixz/claude-db --skill db-query-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db-query-patterns
Source: https://github.com/Hainrixz/claude-db/tree/main/skills/db-query-patterns
Command: npx skills add https://github.com/Hainrixz/claude-db --skill db-query-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill identifies common query anti-patterns that can lead to performance issues in database operations, helping users optimize their queries and improve database performance.

Core Features & Use Cases

  • Detect SELECT *: Identifies queries that fetch all columns, defeating index usage and causing unnecessary load.
  • Identify Structural N+1: Finds queries within loops that could be optimized with joins or batched IN operations.
  • Analyze Pagination Methods: Audits the use of OFFSET pagination and suggests keyset/seek pagination for better performance.
  • Evaluate Non-SARGable Predicates: Detects conditions that prevent index usage and recommends solutions.
  • Use Case: A developer uses this Skill to review a SQL script and identify performance bottlenecks caused by inefficient query patterns.

Quick Start

Run the db-query-patterns skill on your SQL script to detect query anti-patterns.

Frequently Asked Questions about db-query-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect SQL query anti-patterns for database performance optimization?

To detect SQL query anti-patterns, use static analysis to identify inefficient patterns like `SELECT *`, structural N+1 queries, and non-SARGable predicates that cause performance issues. This process requires static analysis and may require runtime verification.

What are non-SARGable predicates and how do they affect database performance?

Non-SARGable predicates are query conditions that prevent index usage, severely degrading database performance. Identifying these predicates through static analysis allows you to rewrite conditions and restore efficient index seeks for relational databases.

How do I identify structural N+1 queries in my SQL scripts?

You can identify structural N+1 queries by analyzing SQL scripts for queries executed within loops. Static analysis detects these patterns and suggests optimizing them with joins or batched `IN` operations to reduce database load.

What is the best way to audit SQL pagination methods for performance?

The best way to audit SQL pagination is to analyze scripts for `OFFSET` pagination usage. Static analysis detects this anti-pattern and suggests implementing `keyset/seek` pagination instead to achieve significantly better database performance.

Can I use static analysis to find queries using SELECT * in relational databases?

Yes, you can use static analysis to find queries using `SELECT *` in relational databases. Detecting this anti-pattern helps optimize queries by preventing unnecessary data load and defeating proper index usage.

When do I need static analysis versus runtime verification for query optimization?

Static analysis is needed initially to detect inefficient SQL query patterns like non-SARGable predicates and structural N+1 issues. Runtime verification may also be required to confirm the actual database performance impact of these identified anti-patterns.