Sql Queries Indexes logo

Sql Queries Indexes

Community
0xBakeer
sql-queries-indexes

Writing correct and fast SQL queries - joins, aggregates, parameters against injection, pagination, N+1 avoidance, and choosing indexes with EXPLAIN in SQLite and PostgreSQL.

Overview

Publisher0xBakeer
RepositoryTandemLLM
Skill namesql-queries-indexes
Stars
75
Forks
14
Bundled files
Instructions only
LicenseAGPL-3.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by 0xBakeer on GitHub. Read the source before you install it.

Installation

Install the Sql Queries Indexes AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/sql-queries-indexes
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/0xBakeer/TandemLLM.git /tmp/TandemLLM
mkdir -p .claude/skills
cp -r /tmp/TandemLLM/packages/library/sql-queries-indexes .claude/skills/sql-queries-indexes
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Sql Queries Indexes in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Sql Queries Indexes on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Sql Queries Indexes is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

SQL queries and indexes

Rules:

  • Parameters always (? or $1), never string formatting with user values.
  • Select the columns you need. SELECT * only in exploration.
  • One query with a JOIN or WHERE id IN (...) instead of one query per row (N+1). Load the list, then the children in one call.
  • Pagination by keyset (WHERE id > $last ORDER BY id LIMIT 50), not by large OFFSET.
  • Index what the WHERE and JOIN filter on, in that order: equality columns first, then the range or sort column. One index per hot query shape; not every column.

What goes wrong:

  • A LEFT JOIN with a condition in WHERE on the right table turns it into an inner join; move the condition into ON.
  • GROUP BY with a column not in the group and not aggregated; wrong or rejected.
  • COUNT(*) over the whole table on every page load; cache or keep a counter.

Check: run the query on real data with timing (\timing or time), show the plan before and after, and compare the row count against a simple counting query.

Done when:

  • The query's rows and time on real data in the result.
  • The EXPLAIN plan shows an index scan (or a seq scan justified by table size under 10k rows).
  • The row count cross-checked by a second, simpler query.

Reference

Children in one query (no N+1):

sql
SELECT u.id, u.name, i.id AS item_id, i.text
FROM users u
LEFT JOIN items i ON i.user_id = u.id AND i.done = false
WHERE u.id = ANY($1)
ORDER BY u.id, i.id;

Aggregate per user with a filter:

sql
SELECT user_id, COUNT(*) FILTER (WHERE done) AS done, COUNT(*) AS total
FROM items GROUP BY user_id HAVING COUNT(*) > 0;

Keyset pagination: SELECT id, text FROM items WHERE user_id = $1 AND id > $2 ORDER BY id LIMIT 50; with index (user_id, id). Plan:

sql
EXPLAIN (ANALYZE, BUFFERS) SELECT ... ;          -- Postgres
EXPLAIN QUERY PLAN SELECT ... ;                  -- SQLite
CREATE INDEX CONCURRENTLY idx_items_user_id ON items(user_id, id);   -- Postgres, no table lock

Python parameters:

python
cur.execute("SELECT id, text FROM items WHERE user_id = ? AND done = ?", (user_id, 0))    # sqlite3
cur.execute("SELECT id, text FROM items WHERE user_id = %s", (user_id,))                   # psycopg

Upsert: INSERT INTO kv(k, v) VALUES ($1, $2) ON CONFLICT (k) DO UPDATE SET v = EXCLUDED.v; Timing: psql -c '\timing' -c "SELECT ..." or time sqlite3 app.db "SELECT ...".

More rules:

  • Prove a slow query with EXPLAIN (ANALYZE) (Postgres) or EXPLAIN QUERY PLAN (SQLite) before and after the index; keep the lines.

More pitfalls:

  • A function on the indexed column (lower(email), date(created_at)) skips the index; index the expression or store the normalized value.
  • Timeouts in a transaction left open; commit or roll back on every path.

Frequently asked questions

What does the Sql Queries Indexes AI skill do?

Writing correct and fast SQL queries - joins, aggregates, parameters against injection, pagination, N+1 avoidance, and choosing indexes with EXPLAIN in SQLite and PostgreSQL.

Why use Sql Queries Indexes on TypingMind?

Because you install it once and use it with any model. Sql Queries Indexes is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Sql Queries Indexes in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/sql-queries-indexes. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Sql Queries Indexes?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Sql Queries Indexes?

As many as you like. As long as a model supports skills, you can use Sql Queries Indexes with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Sql Queries Indexes AI skill free?

Yes. It is published on GitHub by 0xBakeer under the AGPL-3.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇