db-query-patterns

db-query-patterns is a skill for Claude Code from Hainrixz/claude-db. It costs 51 tokens per session (1,047 once invoked), scanned A, original, MIT.

A code-review skill that checks common database-query patterns that can make applications slower. It covers fetching unnecessary columns, repeated queries in loops, deep OFFSET pagination, and conditions that prevent indexes from being used.

In plain words
What is it for?
Use it to audit SQL and ORM code for SELECT *, structural N+1 queries, OFFSET-based pagination, and non-index-friendly filters.
Why use it?
It identifies query shapes that can waste database, network, or application resources and points to safer alternatives such as batching or keyset pagination.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the claude-db plugin — 36 skills, 6 agents, 1 hook shipped together

Good fit Use it to audit SQL and ORM code for SELECT *, structural N+1 queries, OFFSET-based pagination, and non-index-friendly filters.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/hainrixz/claude-db/db-query-patterns
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 Hainrixz/claude-db --skill db-query-patterns
Clone the repo
git clone --depth 1 https://github.com/Hainrixz/claude-db

Made for: Claude Code.

Or install claude-db, the plugin that ships this one along with the rest of its 36 skills, 6 agents, 1 hook.

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 db-query-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/hainrixz/claude-db/db-query-patterns/github.svg)](https://agentmods.dev/skills/hainrixz/claude-db/db-query-patterns)
Your own site
<a href="https://agentmods.dev/skills/hainrixz/claude-db/db-query-patterns"><img src="https://agentmods.dev/badge/skills/hainrixz/claude-db/db-query-patterns/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 db-query-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/hainrixz/claude-db/db-query-patterns"><img src="https://agentmods.dev/badge/skills/hainrixz/claude-db/db-query-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,047 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.
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.00051 $0.01047
Opus 5.5 $0.00020 $0.00419
Sonnet 5.5 $0.00010 $0.00209
Haiku 4.5 $0.00005 $0.00105

Measured yesterday against content hash b0d971f89074, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

db-query-patterns 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 yesterday.

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.

skills/db-query-patterns/SKILL.md · 73 lines

How it starts

The opening of the file, as written. The whole thing — 73 lines — stays where its author put it; the contents beside it link to each section on GitHub.

db-query-patterns (M13)

How queries are written decides whether the indexes from M11 can even be used. This module inspects query shape in ORM source and raw SQL. Feeds the Performance & Scale score (axis performance, relational Query w18, shared with M3/M19).

What it checks

  1. SELECT * — fetching all columns defeats covering indexes, bloats network/cache, and couples code to column order. Flag in hot paths.
  2. Structural N+1 — a query inside a loop / per-row lazy relation load that should be a single join or batched IN. Static detection is directional (the loop's runtime cardinality is unknown) — it points at the structure, never claims a row count.
  3. OFFSET pagination — LIMIT n OFFSET m degrades linearly with depth; deep pagination should use keyset/seek (WHERE id > $last ORDER BY id LIMIT n).
  4. Non-SARGable predicates — wrapping the indexed column in a function (WHERE lower(email)=…, WHERE date(created_at)=…, leading-wildcard LIKE '%x', implicit type cast) so the index can't be used. Recommend an expression index or rewriting the predicate. For the leading-wildcard / LIKE '%x%' case a B-tree can never help — name the remedy: a pg_trgm GIN/GiST index on the column (or a dedicated search engine for heavy full-text search).

Score / axis

Feeds performance only (relational Query w18; Query category in document/time-series/graph profiles).

Tier-0 (static)

Grep ORM call sites and raw SQL for SELECT *, function-wrapped indexed columns, leading-wildcard LIKE, and OFFSET; detect query calls inside loops/.map/per-item relation access for N+1. All query-pattern findings are at most directional from source — confirming the actual plan/cost needs runtime (needs_api / Tier-2).

Tier-1/2 (verification query)

EXPLAIN (ANALYZE, BUFFERS) <the suspect query>;

Method explain_plan. A Seq Scan where an index exists confirms a non-SARGable predicate; the actual rows × loops confirms an N+1 amplification. Tier-2 pg_stat_statements (ordered by total_exec_time) surfaces the real hot queries — without it, hotness is directional.

Read the full file on GitHub · 73 lines

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. yesterday Changed · +1 lines b0d971f89074
  2. 1mo ago First seen · 72 lines · 51 tokens per session scan A a7ec8e6b7dfc

Subscribe to this mod's changes

db-query-patterns is a skill published in the GitHub repository Hainrixz/claude-db (21 stars, last pushed 2d ago), licensed MIT. It adds 51 tokens to every session and 1,047 once invoked, about $0.0002 per session on Opus 5.5. 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

malloy-lookml-review

Analyze LookML files as prior art for Malloy modeling. Used during Step 1 (DISCOVER) when .lkml files are present. Coordinates reference files that extract business logic, relationships, and curation decisions. Works with or without a database connection.

malloydata/publisher · 58 tokens

triage-contributor-pr

Triage open pull requests from external contributors to prisma/orm and produce a per-PR verdict with evidence. Use when a maintainer asks to triage, evaluate, assess, or review the queue of incoming contributor PRs, to decide whether a fork PR is safe to run CI on, to check whether a PR is in scope for its version…

prisma/orm · 131 tokens

review-implement-phase

Implements triaged review actions, commits focused fixes, and posts Done plus resolves threads. Use when the user wants only the implementation phase of the review-framework workflow.

prisma/orm · 38 tokens

no-bare-casts

Writing as in TypeScript or TSX production code, modifying a file that contains a bare as cast, silencing a type error with a cast, encountering as unknown as, or reviewing a cast site.

prisma/orm · 52 tokens

review-prs

Review a GitHub pull request in the googleapis/mcp-toolbox repo against the team's reviewer checklist: PR title/description conventions, linked issue, logic errors and unhandled edge cases, breaking changes, test coverage, docs updates, security (input handling), and new dependencies. Use whenever a maintainer asks…

googleapis/mcp-toolbox · 162 tokens

migration-review

Review database migration files when a change adds or modifies paths under migrations/. Use it before merge to collect forward, rollback, locking, and data-safety evidence.

rohitg00/ai-engineering-from-scratch · 35 tokens