跳到主要内容
知仓学习社ZHICANG

sql-query-explainer

Explains, optimises, writes, and documents SQL queries. Use when asked to explain a SQL query, optimise slow SQL, translate SQL to plain English for…

不碰外部(只输出文字)无严重或高危命中mohitagw15856/pm-claude-skills

它会碰到什么

扫了多少1 个文本文件,6 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

SQL Query Explainer Skill

This skill explains SQL queries in plain language, identifies optimisation opportunities, and helps communicate data logic to non-technical stakeholders. It also writes and documents new queries from natural language descriptions.

Required Inputs

  • The SQL (Explain/Optimise/Document modes) — the actual query, ideally with the dialect named (Postgres, BigQuery, Snowflake, MySQL…); dialect changes both semantics and the optimisation advice.
  • The intent in plain words (Write mode) — what question the data should answer, plus table/column names if known. Without a schema, assumptions get stated, never silently invented.
  • Optional but transformative: EXPLAIN/EXPLAIN ANALYZE output and rough table sizes — turns generic advice into advice about your query plan.

Modes

Detect which mode the user needs based on their request:

  1. Explain — Translate existing SQL into plain English
  2. Optimise — Review SQL for performance issues and suggest improvements
  3. Write — Generate SQL from a natural language description
  4. Document — Produce a data dictionary or query documentation

Mode 1: Explain

When given a SQL query, produce:

Plain English Summary

[1–3 sentences. What does this query do? What data does it return? Write as if explaining to a business analyst, not a developer.]

Step-by-Step Walkthrough

Break the query into logical sections. For each section:

  • Quote the SQL clause
  • Explain what it does in plain English
  • Flag any complexity (e.g. window functions, subqueries, CTEs)

What the Result Looks Like

[Describe the shape of the output: "Returns one row per user, with columns for X, Y, Z. Ordered by [field] descending."]

Potential Issues to Flag

  • [Gotchas, edge cases, or implicit assumptions in this query]
  • [e.g. "This will include NULLs in the user_id column if the LEFT JOIN finds no match"]

Mode 2: Optimise

When asked to optimise a query, produce:

Performance Assessment

Rate overall: 🟢 Well-optimised / 🟡 Some improvements possible / 🔴 Significant issues

Issues Found

For each issue:

Issue [N]: [Short name, e.g. "Missing index on join column"]

  • What it is: [Plain explanation]
  • Why it matters: [Performance impact — e.g. "Full table scan on a 10M row table"]
  • Fix:
-- Before
[original snippet]

-- After
[improved snippet]
  • Expected improvement: [Estimate if possible]

Optimisation Checklist

  • [ ] SELECT * used? (Replace with specific columns)
  • [ ] Implicit type conversions on JOIN/WHERE columns?
  • [ ] Missing indexes on JOIN or WHERE columns?
  • [ ] N+1 patterns (queries inside loops)?
  • [ ] DISTINCT used where GROUP BY would be faster?
  • [ ] Window functions used where a subquery would be clearer/faster?
  • [ ] CTEs re-used or materialised unnecessarily?
  • [ ] Large IN() lists that could use a JOIN instead?

Mode 3: Write

When given a natural language description, generate the SQL query and then explain it using Mode 1.

Ask the user to confirm:

  • Database/dialect (PostgreSQL / MySQL / BigQuery / Snowflake / SQLite / Standard SQL)
  • Table and column names (if known; otherwise use descriptive placeholder names like users, orders, user_id)
  • Any filters, sorting, or aggregation requirements

Produce:

  1. The SQL query with inline comments
  2. Plain English explanation (Mode 1 format)

Mode 4: Document

When asked to create documentation for a query or table:

Query Documentation

Query: [Name]
Purpose: [One sentence — what business question this answers]
Author: [If provided]
Last reviewed: [If provided]

Inputs:
  - Table: [table_name] — [what it contains]
  - Filter: [any WHERE conditions and their business meaning]

Output columns:
  | Column | Type | Description |
  |--------|------|-------------|
  | [name] | [type] | [plain English description] |

Assumptions:
  - [Any implicit assumptions the query makes]

Known limitations:
  - [Edge cases not handled, data quality dependencies, etc.]

Output Format

Every mode returns the same disciplined shape:

  1. The one-line summary — what this query does, in business language ("monthly revenue per region, excluding refunds"), before any SQL talk.
  2. The walkthrough or the artifact — mode-dependent: annotated clause-by-clause explanation (Explain), the rewritten query with a diff of what changed and why (Optimise), the new query with stated assumptions (Write), or the doc block (Document).
  3. The gotchas — NULL behaviour, join fan-out, timezone traps, and index implications that apply to this query, not generic advice.
  4. Verification — a small SELECT the user can run to confirm the query does what the summary claims (row counts before/after, a spot-check predicate).

Quality Checks

  • [ ] Plain English explanation avoids SQL jargon
  • [ ] Optimisation suggestions include before/after SQL
  • [ ] Written queries include inline comments
  • [ ] Output shape is described (columns, row grain, ordering)
  • [ ] Dialect-specific syntax is flagged when non-standard

Anti-Patterns

  • Restating the SQL in pseudo-code instead of explaining what it does and returns
  • Optimisation advice with no before/after query, or no reason the new one is faster
  • Ignoring the dialect (writing Postgres-only syntax for a MySQL user)
  • "Looks fine" with no read on correctness, performance, or row grain
  • Rewriting the query from scratch instead of explaining/optimising the user's

Example Trigger Phrases

  • "Explain this SQL query: [paste query]"
  • "Optimise this slow query: [paste query]"
  • "Write a SQL query that [natural language description]"
  • "Document this query for my non-technical stakeholders"
  • "Why is this query returning unexpected results?"

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

同名技能的其他版本

有 3 个不同仓库或目录里都有叫 sql-query-explainer 的技能。它们内容并不相同,别混用: