Agent skill

SQL Query Performance

by makifbaysal in makifbaysal/tasktrooper

A skill your agent uses when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination

Apache-2.0Auto-check passedDatabases

Install SQL Query Performance

skills CLI
$ npx skills add makifbaysal/tasktrooper --skill sql-query-performance -a claude-code

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

GitHub CLI
$ gh skill install makifbaysal/tasktrooper sql-query-performance --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/makifbaysal/tasktrooper.git skills-src && mkdir -p .claude/skills && cp -r skills-src/catalog/agents/backend-developer/skills/sql-query-performance .claude/skills/sql-query-performance && 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
sql-query-performance
GitHub stars
109
Token cost
~1.1k tokens
SKILL.md length
529 words
Files
1
Skills in repo
99
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination

  • Changing a query against PostgreSQL from Go — avoiding N+1 loops
  • SKILL.md covers Overview, N+1 in Go, Database hygiene and Reading EXPLAIN, plus 5 more sections
  • Calls psql
  • Reading EXPLAIN output

What it does

SQL Query Performance is an agent skill from makifbaysal/tasktrooper. Use when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination

Its SKILL.md is about 1.1k 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 SQL. It works with SQL and PostgreSQL. The repository describes itself as: Local-first agent platform: board + role agents + agent CLI runs (Claude Code, Cursor, Antigravity, OpenCode) or local and API models (Ollama, LM Studio), all on your own Mac. The licence is Apache-2.0.

When your agent uses it

  • Changing a query against PostgreSQL from Go — avoiding N+1 loops
  • Reading EXPLAIN output
  • Keyset pagination

Example prompts

  • “/sql-query-performance”

What it can do on your machine

Read from SKILL.md and the folder at commit 09f6258. 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

    Shell commands in SKILL.md call:

    • psql

    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

SQL Query Performance loads about 1.1k tokens when it runs. Until then it costs about 41 tokens; SKILL.md has 529 words of instructions outside code blocks.

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

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 makifbaysal/tasktrooper at commit 09f6258, republished under its Apache-2.0 licence (© makifbaysal). 529 words, ~1,090 tokens.

Download SKILL.mdSave it as .claude/skills/sql-query-performance/SKILL.md (or your agent's skills folder).
name
sql-query-performance
description
Use when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination
category
database
tech_stack
PostgreSQL
source
samber/cc-skills-golang golang-database (MIT), wshobson/agents sql-optimization-patterns (MIT), adapted

SQL Query Performance (Go)

Overview

Go has no ORM to blame for an N+1 — it's a loop you wrote yourself, calling the repository once per item instead of once for the batch. This skill is the Go-side half of query performance; java-persistence covers the JPA/Hibernate side.

Core principle: one round trip per request-shaped operation, not one per row.

N+1 in Go

go
// ❌ one query per item: N+1
for _, id := range ids {
    task, err := repo.Get(ctx, id)   // round trip per id
    ...
}

// ✅ one query for the batch
tasks, err := repo.GetMany(ctx, ids)   // SELECT ... WHERE id = ANY($1)
sql
SELECT id, title, status FROM tasks WHERE id = ANY($1);

Bind ids as a []uuid.UUID (pgx encodes a Go slice as a Postgres array directly — no manual IN (...) string building). For a write-side batch, use pgx.Batch to pipeline multiple statements over one round trip instead of looping with individual Exec calls.

Database hygiene

  • Every call takes a context.Context — QueryContext/ExecContext (database/sql) or pgx's ctx parameter — so a slow query is cancelable and traceable.
  • defer rows.Close() immediately after a successful Query, and check rows.Err() after the loop — a Query that returns rows can still fail mid-stream, and an unclosed Rows leaks the connection.
  • Use Exec, not Query, for statements that return no rows (INSERT/UPDATE/DELETE without RETURNING) — Query leaves a result set open that must still be drained.
  • No SELECT * in application code — name the columns, so an added column doesn't silently change scan order or payload size.

Reading EXPLAIN

psql "$DATABASE_URL" -c "EXPLAIN (ANALYZE, BUFFERS) <query with literal values, not placeholders>"

Run it against realistically seeded data, not an empty table — an empty-table plan hides the index Postgres would actually need. Read for:

  • Seq Scan on a table bigger than a few thousand rows → missing index.
  • Estimated vs actual row counts far apart → stale statistics (ANALYZE <table>) or a predicate the planner can't estimate well.
  • A Sort that spills to disk (Sort Method: external merge) → needs work_mem tuning or an index that avoids the sort.
Show full SKILL.md (257 more words)Show less

Indexes

  • Postgres does not auto-index foreign-key columns — add one explicitly for every FK you join or filter on.
  • Composite index column order follows the leftmost-prefix rule: an index on (a, b) serves queries filtering on a alone or a AND b, not b alone.
  • A partial index (WHERE status = 'open') for a hot subset of a much larger table.
  • A covering index (INCLUDE (col)) to let an index-only scan satisfy a query without a heap fetch.

See postgres-migrations for how to add an index on a live table without locking it.

Query-count regression test

Wrap the pool/connection to count statements in a test, or use pg_stat_statements where the test DB has it enabled, and assert the count stays constant as the dataset grows — this is what catches an N+1 before it ships, the same way java-persistence's Hibernate-statistics assertion does on the Java side.

Keyset pagination

See api-design-conventions for the full pagination guidance; the query shape is:

sql
SELECT ... FROM tasks
WHERE (created_at, id) < ($1, $2)
ORDER BY created_at DESC, id DESC
LIMIT $3 + 1;   -- fetch one extra row to know has_more

Common Mistakes

  • A loop calling the repository once per id instead of a batched = ANY($1) query.
  • rows.Close() missing or only deferred conditionally (e.g. after an early if err != nil { return } that skips the defer).
  • rows.Err() never checked after the loop.
  • Adding a filter/join column with no matching index.
  • Reading EXPLAIN against an empty or tiny local table and concluding the query is fine.

Red Flags

  • Query count in a test or log scales linearly with row count.
  • Seq Scan on a table expected to hold more than a few thousand rows.
  • A new WHERE/JOIN column with no migration adding its index.

© makifbaysal, Apache-2.0. 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 catalog/agents/backend-developer/skills/sql-query-performance of makifbaysal/tasktrooper.

Open the folder on GitHubat commit 09f6258

Compare with similar skills

SQL Query Performance 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.

SQL Query Performance compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL Query Performance this skillmakifbaysal/tasktrooper109—~1.1kAutomated safety check: PassApache-2.0
Safe SQL Executionsupabase/supabase111k—~4.2kAutomated safety check: PassApache-2.0
Sql2erystemsrx/sql_to_ER1881 repos~1.1kAutomated safety check: PassAGPL-3.0
SQL Database Support for pRESTprest/prest4.6k—~1.6kAutomated safety check: PassMIT
Chdb SQLvemetric/vemetric3941 repos~1.2kAutomated safety check: PassApache-2.0
Mz BenchmarkMaterializeInc/materialize6.4k—~2.8kAutomated safety check: PassCustom licence

Similar skills

  • Safe SQL Execution

    supabase/supabase

    Official

    A skill your agent uses whenever code will build, return, fetch, or execute SQL that runs against a user's real Postgres database — even when the request reads like an ordinary feature or bug fix…

    111k GitHub stars~4.2k tokensUpdated today
    DatabasesAuto-check passed
  • Sql2er

    ystemsrx/sql_to_ER

    A skill your agent uses when the user wants a Chen-model ER diagram from SQL CREATE TABLE statements or DBML, wants to rearrange or clean up an existing sql2er state, wants a skeleton-only overview…

    188 GitHub starsUsed in 1 repo~1.1k tokens
    DatabasesAuto-check passed
  • Guides classifying, gap-analyzing and scaffolding support for a new SQL database in pREST, from Postgres-compatible variants to entirely new dialects.

    4.6k GitHub stars~1.6k tokensUpdated today
    DatabasesAuto-check passed
  • Chdb SQL

    vemetric/vemetric

    A skill your agent uses when the user wants to run SQL — especially analytical SQL — on local files (parquet/csv/json), URLs, S3 paths, or remote databases (Postgres, MySQL, MongoDB, ClickHouse…

    394 GitHub starsUsed in 1 repo~1.2k tokens
    DatabasesAuto-check passed
  • Mz Benchmark

    MaterializeInc/materialize

    Add/modify/debug Materialize perf benchmark scenarios. An agent skill from MaterializeInc/materialize.

    6.4k GitHub stars~2.8k tokensUpdated today
    DatabasesAuto-check passed
  • Schema Exploration

    timescale/pg-aiguide

    Explore an existing PostgreSQL database before answering questions about its data or writing SQL.

    1.9k GitHub stars~1.1k tokensUpdated today
    DatabasesAuto-check passed

More from makifbaysal/tasktrooper

All 99 skills in this repo
  • API Contract Testing

    makifbaysal/tasktrooper

    A skill your agent uses when a task adds or changes an HTTP endpoint, its request/response shape, status codes, auth or error format - the request matrix, curl templates and what counts as a…

    109 GitHub starsUsed in 1 repo~771 tokens
    Auto-check passed
  • Acceptance Criteria Gwt

    makifbaysal/tasktrooper

    A skill your agent uses when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases

    109 GitHub stars~1.7k tokensUpdated today
    Auto-check passed
  • Accessibility Check

    makifbaysal/tasktrooper

    A skill your agent uses when a task changes any screen, form, dialog, menu or control - Lighthouse/axe scan of the changed screens, a keyboard walk, and the thresholds that fail a task

    109 GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Analiz Gate

    makifbaysal/tasktrooper

    A skill your agent uses when deciding whether a request needs an analiz task before implementation - the conditions that require the architect's analysis versus going straight to implementation

    109 GitHub stars~641 tokensUpdated today
    Auto-check passed
  • Analiz HTML Report

    makifbaysal/tasktrooper

    A skill your agent uses when you write or revise the analiz deliverable - the ONE self-contained HTML report (spec and plan as sections) a human reviews passage by passage

    109 GitHub stars~3.9k tokensUpdated today
    Auto-check passed
  • Analiz Human Review Gate

    makifbaysal/tasktrooper

    A skill your agent uses when you finish an analiz report - the human must approve the analysis before any implementation task is created, via the analizreview column

    109 GitHub stars~2.2k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about SQL Query Performance

What does SQL Query Performance do?

A skill your agent uses when writing or changing a query against PostgreSQL from Go — avoiding N+1 loops, reading EXPLAIN output, indexing, and keyset pagination. SQL Query Performance is an agent skill from makifbaysal/tasktrooper.

When should I use SQL Query Performance?

SQL Query Performance fits situations like: changing a query against PostgreSQL from Go — avoiding N+1 loops; reading EXPLAIN output; keyset pagination.

How do I install SQL Query Performance in Claude Code?

Run `npx skills add makifbaysal/tasktrooper --skill sql-query-performance -a claude-code`. Or copy the skill folder (catalog/agents/backend-developer/skills/sql-query-performance in makifbaysal/tasktrooper) into .claude/skills/sql-query-performance in your project. Claude Code loads it when a task matches its description.

How do I install SQL Query Performance in Codex?

Run `npx skills add makifbaysal/tasktrooper --skill sql-query-performance -a codex`. Or copy the skill folder (catalog/agents/backend-developer/skills/sql-query-performance in makifbaysal/tasktrooper) into .agents/skills/sql-query-performance in your project. Codex loads it when a task matches its description.

Can I use SQL Query Performance 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 makifbaysal/tasktrooper --skill sql-query-performance -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-query-performance, .gemini/skills/sql-query-performance, .github/skills/sql-query-performance and .opencode/skills/sql-query-performance in your project.

What does SQL Query Performance need to run?

Going by SKILL.md and its folder, SQL Query Performance needs the command-line tools its instructions call (psql).

Does SQL Query Performance 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 SQL Query Performance 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 SQL Query Performance use?

SQL Query Performance is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL Query Performance use?

About 1.1k tokens (SKILL.md is roughly 4.4k 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 SQL Query Performance?

Skills that share tags, products or a category with SQL Query Performance: Safe SQL Execution (supabase/supabase, 111k stars), Sql2er (ystemsrx/sql_to_ER, 188 stars), SQL Database Support for pREST (prest/prest, 4.6k stars) and Chdb SQL (vemetric/vemetric, 394 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL Query Performance?

makifbaysal (a GitHub user) maintains it in makifbaysal/tasktrooper, which has 109 GitHub stars. The repository holds 99 skills in this directory. The repository was last updated on October 7, 2026.

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