Skip to content
Agentmart
Submit a tool

query-optimization

查询优化指南 —— 慢查询分析、索引调优、执行计划解读与 N+1 问题治理

Skill by Sweetteabittersugar

IndexedMIT★ 3
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/sweetteabittersugar-query-optimization

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

查询优化指南 —— 慢查询分析、索引调优、执行计划解读与 N+1 问题治理

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/query-optimization

What's inside

Skill name
query-optimization
Description
查询优化指南 —— 慢查询分析、索引调优、执行计划解读与 N+1 问题治理
License
MIT
Instructions
32 lines in SKILL.md · view on GitHub

Files (2)

  • SKILL.md
  • SKILL.md.disabled

SKILL.md (first lines)

# 查询优化指南

## 概述
提供数据库查询性能优化的系统化方法论,覆盖从慢查询定位、执行计划分析、索引设计到 ORM N+1 问题的全链路优化。

## 使用场景
- 线上数据库负载过高需要定位慢查询
- 接口响应时间异常需要排查 SQL 性能
- 索引设计评审和优化建议
- ORM 查询的 N+1 问题排查和修复

## 核心原则
1. **先测量再优化**:没有执行计划(EXPLAIN)数据的优化是盲目的。永远基于指标而非直觉做决策。
2. **索引是最廉价的优化**:在查询频繁且过滤性好的列上建立索引,收益远高于代码层面的优化。
3. **减少数据传输量**:`SELECT *` 是性能杀手——只查需要的列;分页必须有合理的 LIMIT。
4. **避免循环查询(N+1)**:ORM 懒加载是 N+1 的主要来源。使用 JOIN 或批量预加载(`prefetch_related` / `eager loading`)替代。
5. **覆盖索引最大化**:如果索引包含查询所需的所有列,则无需回表查询,性能提升数倍。

## 常见优化手段
- **执行计划分析**:关注 `type`(range > index > ALL)、`rows`(扫描行数)、`Extra`(Using filesort 是坏信号)
- **联合索引**:遵循最左前缀原则,高选择性的列放左侧
- **分页优化**:大 offset 用游标分页或 `WHERE id > last_id LIMIT n` 替代 `OFFSET`
- **查询重写**:子查询改 JOIN、OR 改 UNION、避免函数操作索引列

## 检查清单
- [ ] 是否通过 EXPLAIN 分析了所有核心查询的执行计划?
- [ ] 是否存在未使用索引的全表扫描(type=ALL)?
- [ ] 是否存在 N+1 查询(ORM 循环加载关联数据)?
- [ ] 分页查询是否有合理的 LIMIT 和索引支持?
- [ ] 是否有慢查询日志的监控和告警机制?

From Sweetteabittersugar/agency, MIT.

More from Sweetteabittersugar/agency

Signals

Stars
3
Forks
1
Open issues
0
Last commit (this folder)
Jun 10, 2026 (4 months ago)
Last release
Aug 24, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Sweetteabittersugar

Cite this page

query-optimization skill. Agent Mart. https://agentmart.dev/skills/sweetteabittersugar-query-optimization (last updated 2026-10-24)