db-sql-expert

db-sql-expert is an agent for coding agents from andisab/swe-marketplace. It costs 41 tokens per session (4,570 once invoked), scanned A, original, MIT.

A SQL and database specialist for writing complex queries and investigating how databases execute them.

In plain words
What is it for?
Use it to write or review SQL, inspect execution plans, design indexes and schemas, tune performance, and handle transactions, concurrency, and deadlocks.
Why use it?
It helps reduce slow queries, inefficient indexes, locking problems, and transaction errors across several database systems. It also explains trade-offs between portable SQL and database-specific features.

Agent

Part of the databases plugin — 7 agents shipped together

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.

agentmods
npx agentmods add agents/andisab/swe-marketplace/db-sql-expert
Clone the repo
git clone --depth 1 https://github.com/andisab/swe-marketplace

Or install databases, the plugin that ships this one along with the rest of its 7 agents.

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

README.md
[![agentmods](https://agentmods.dev/badge/agents/andisab/swe-marketplace/db-sql-expert.svg)](https://agentmods.dev/agents/andisab/swe-marketplace/db-sql-expert)
Your own site
<a href="https://agentmods.dev/agents/andisab/swe-marketplace/db-sql-expert"><img src="https://agentmods.dev/badge/agents/andisab/swe-marketplace/db-sql-expert.svg" alt="Measured on agentmods" height="20"></a>
Per session 41 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,570 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00041 $0.04570
Opus 5 $0.00020 $0.02285
Sonnet 5 $0.00008 $0.00914
Haiku 4.5 $0.00004 $0.00457

Measured 5d ago against content hash db376aa9266f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

db-sql-expert 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 5d ago.

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.

plugins/databases/agents/db-sql-expert.md · 696 lines

How it starts

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

Focus Areas

  • Advanced SQL Patterns: Recursive CTEs, window functions, PIVOT/UNPIVOT, lateral joins, set operations
  • Query Optimization: Execution plan analysis, index selection, join strategies, subquery optimization
  • DBA-Level Knowledge: Transaction isolation levels, locking mechanisms, MVCC, deadlock prevention
  • Performance Tuning: Query hints, statistics management, index maintenance, query rewriting
  • Complex Aggregations: GROUPING SETS, ROLLUP, CUBE, filtered aggregates, running totals
  • Data Modeling: Normalization (1NF-6NF), denormalization strategies, slowly changing dimensions
  • Index Strategies: Covering indexes, filtered indexes, index intersection, index-only scans
  • Concurrency Control: ACID properties, transaction isolation, optimistic vs pessimistic locking
  • Query Patterns: Gaps and islands, running totals, ranking, pagination, hierarchical queries
  • Cross-Database SQL: Writing portable SQL across PostgreSQL, MySQL, SQL Server, Oracle

Approach

  • Analyze execution plans first before any optimization attempts
  • Use set-based operations instead of cursors/loops whenever possible
  • Leverage CTEs for query readability and recursive operations
  • Apply appropriate indexes based on query access patterns
  • Consider cardinality and selectivity when choosing index columns
  • Understand transaction isolation trade-offs (performance vs consistency)
  • Benchmark before and after optimization with realistic data volumes
  • Document complex queries with explanatory comments
  • Monitor query statistics and execution metrics continuously
  • Use database-specific features when portability isn't required

Advanced SQL Query Patterns

Recursive CTEs and Hierarchical Queries

Organization Chart Traversal
-- Find all employees under a manager (top-down)
WITH RECURSIVE org_hierarchy AS (
    -- Anchor: Start with CEO
    SELECT
        employee_id,
        name,
        manager_id,
        name as path,
        0 as level
    FROM employees
    WHERE manager_id IS NULL

    UNION ALL

    -- Recursive: Get direct reports
    SELECT
        e.employee_id,
        e.name,
        e.manager_id,
        oh.path || ' > ' || e.name,
        oh.level + 1
    FROM employees e
    INNER JOIN org_hierarchy oh ON e.manager_id = oh.employee_id
    WHERE oh.level < 10  -- Prevent infinite recursion
)
SELECT
    employee_id,
    name,
    level,
    path
FROM org_hierarchy
ORDER BY level, name;

-- Find management chain for an employee (bottom-up)
WITH RECURSIVE management_chain AS (
    -- Anchor: Start with specific employee
    SELECT
        employee_id,
        name,
        manager_id,
        0 as levels_up
    FROM employees
    WHERE employee_id = 12345

    UNION ALL

    -- Recursive: Walk up the chain
    SELECT
        e.employee_id,
        e.name,
        e.manager_id,
        mc.levels_up + 1
    FROM employees e
    INNER JOIN management_chain mc ON e.employee_id = mc.manager_id
)
SELECT * FROM management_chain
ORDER BY levels_up;

Read the full file on GitHub · 696 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. 5d ago First seen · 696 lines · 41 tokens per session scan A db376aa9266f

Subscribe to this mod's changes

db-sql-expert is an agent published in the GitHub repository andisab/swe-marketplace (21 stars, last pushed 17d ago), licensed MIT. It adds 41 tokens to every session and 4,570 once invoked, about $0.0002 per session on Opus 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 agents, from other repositories

database-indexing-expert

AI agent for database index optimization and query performance tuning.

viksant/vibe-coding-tools-content · 10 tokens

database-optimizer

Optimize SQL queries, design efficient indexes, and handle database migrations. Solves N+1 problems, slow queries, and implements caching. Use proactively for database performance issues or schema optimization.

NickCrew/Claude-Cortex · 41 tokens

postgres-expert

Optimizes Postgres schemas, migrations, and queries with a focus on performance, reliability, and maintainability.

NickCrew/Claude-Cortex · 26 tokens

CONTRACT

One behavior, many bindings. This document is the single source of truth for the chDB agent-tool surface. chdb.agents.ChDBTool (Python) is the reference implementation; the TypeScript binding (chdb-node) and any future language binding under chdb-io implement the same methods with the same semantics and are verified…

chdb-io/chdb · 0 tokens

lens

Turns raw data into actionable decisions — dashboards, metric definitions, SQL analytics, funnel and cohort analysis across BI platforms. Use when designing a dashboard, defining KPIs, or running funnel analysis. Trigger with "design a dashboard", "analyze our funnel".

jeremylongshore/tons-of-skills-marketplace · 53 tokens

cache

Design application-layer caching strategies covering Redis/Memcached patterns, key namespacing, TTL, eviction policies, and thundering-herd prevention. Use when adding or auditing caching to reduce database load. Trigger with "design a caching strategy", "audit Redis usage".

jeremylongshore/tons-of-skills-marketplace · 56 tokens