Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问许可证需确认审计通过

analyzing-database-indexes分析数据库索引

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

713

周安装

30

GitHub Stars

2,077

下载量

250
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:analyzing-database-indexes(分析数据库索引)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/analyzing-database-indexes
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill analyzing-database-indexes
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill analyzing-database-indexes

简介

用于分析数据库索引使用情况,识别缺失或冗余索引。

  • 支持 PostgreSQL 和 MySQL,提供性能优化建议。
  • 基于 pg_stat_* 系统视图或 performance_schema 生成分析报告。
  • 需要数据库凭据和查询统计扩展已启用。analyzing-database-indexes 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 建议在非高峰时段运行,避免影响生产环境性能。

SKILL.md

Database Index Advisor

Overview

Analyze database index usage, identify missing indexes causing sequential scans, detect redundant or unused indexes wasting write performance, and recommend optimal index configurations for PostgreSQL and MySQL.

Prerequisites

  • Database credentials with access to pg_stat_user_indexes, pg_stat_user_tables, and pg_stat_statements (PostgreSQL) or performance_schema and sys schema (MySQL)
  • pg_stat_statements extension enabled for PostgreSQL query statistics
  • psql or mysql CLI for executing analysis queries
  • Representative workload running (analysis during off-peak hours may miss important query patterns)
  • At least 24 hours of statistics accumulation since the last pg_stat_reset()

Instructions

  1. Identify tables with high sequential scan activity (candidates for missing indexes):

- PostgreSQL: SELECT relname, seq_scan, seq_tup_read, idx_scan, n_live_tup FROM pg_stat_user_tables WHERE seq_scan > 100 AND n_live_tup > 10000 ORDER BY seq_tup_read DESC LIMIT 20 - A table with high seq_scan count and high seq_tup_read relative to n_live_tup is scanning most of the table repeatedly

  1. Find the queries causing sequential scans by correlating with pg_stat_statements:

- SELECT query, calls, mean_exec_time, rows FROM pg_stat_statements WHERE query ILIKE '%table_name%' ORDER BY mean_exec_time DESC LIMIT 10 - Run EXPLAIN (ANALYZE, BUFFERS) on the top queries to confirm sequential scan usage

  1. Analyze query WHERE clauses and JOIN conditions to determine which columns need indexes. Extract the filtering columns and their selectivity:

- SELECT column_name, n_distinct, correlation FROM pg_stats WHERE tablename = 'target_table' - High n_distinct (close to row count) indicates good index selectivity - correlation close to 1.0 or -1.0 suggests the column benefits from a B-tree index

  1. Recommend composite indexes for multi-column queries. Follow the equality-first, range-second ordering:

- Place columns used with = operators first in the index - Place columns used with >, <, BETWEEN, or LIKE 'prefix%' last - Example: WHERE status = 'active' AND created_at > '2024-01-01' -> CREATE INDEX ON orders (status, created_at)

  1. Identify unused indexes wasting write performance:

- PostgreSQL: SELECT indexrelname, idx_scan, pg_size_pretty(pg_relation_size(indexrelid)) AS index_size FROM pg_stat_user_indexes WHERE idx_scan = 0 AND indexrelname NOT LIKE '%pkey' ORDER BY pg_relation_size(indexrelid) DESC - Indexes with zero scans over a representative period are candidates for removal (verify they are not used by foreign key constraints or unique enforcement)

  1. Detect redundant indexes where one index is a prefix of another:

- A single-column index on (customer_id) is redundant if a composite index on (customer_id, created_at) exists, because the composite index serves both single-column and multi-column queries - Generate DROP INDEX recommendations for the redundant subset indexes

  1. Evaluate partial indexes for filtered queries. If a query always filters WHERE status = 'active':

- CREATE INDEX idx_orders_active ON orders (created_at) WHERE status = 'active' - Partial indexes are smaller and faster than full indexes when the filter eliminates most rows

  1. Consider covering indexes (INCLUDE clause in PostgreSQL 11+) for index-only scans:

- CREATE INDEX idx_orders_covering ON orders (customer_id, created_at) INCLUDE (total_amount, status) - The INCLUDE columns are stored in the index leaf pages, enabling index-only scans without heap access

  1. Estimate the impact of each recommendation:

- Index size: SELECT pg_size_pretty(pg_relation_size('index_name')) for existing similar indexes - Write overhead: each additional index adds approximately 5-15% write latency per INSERT/UPDATE - Read improvement: compare EXPLAIN plans with and without the proposed index

  1. Generate a prioritized recommendations report with CREATE INDEX and DROP INDEX statements, estimated storage impact, expected query improvement, and write overhead trade-off analysis.

Output

  • Missing index recommendations as ready-to-execute CREATE INDEX statements with CONCURRENTLY option
  • Unused index report with DROP INDEX candidates and their storage savings
  • Redundant index report identifying prefix-overlapping indexes
  • Index usage statistics showing scan counts, tuple reads, and sizes for all indexes
  • Impact analysis estimating read improvement vs. write overhead for each recommendation

Error Handling

ErrorCauseSolution
pg_stat_statements not availableExtension not installedCREATE EXTENSION pg_stat_statements and add to shared_preload_libraries
Index creation blocks writesCREATE INDEX acquires exclusive lock on the tableUse CREATE INDEX CONCURRENTLY which does not block writes (takes longer but safe for production)
Index not used after creationStatistics not updated or query planner choosing sequential scanRun ANALYZE table_name; check random_page_cost setting (reduce to 1.1 for SSD); verify query uses indexed columns without functions
Statistics reset unexpectedlypg_stat_reset() called or database restart cleared statsWait 24-48 hours for statistics to accumulate; set up periodic stats collection to a metrics table
Too many indexes on write-heavy tableEach INSERT/UPDATE must update all indexesTarget 5-7 indexes per table maximum; use composite indexes to replace multiple single-column indexes; remove unused indexes

Examples

Identifying a missing composite index for an API endpoint: The /orders?customer_id=123&status=active endpoint takes 2 seconds. Analysis shows the orders table (5M rows) has indexes on (id) and (customer_id) but not (customer_id, status). The query filters on both columns. Adding CREATE INDEX CONCURRENTLY idx_orders_customer_status ON orders (customer_id, status) reduces the query to 5ms.

Cleaning up 8 unused indexes saving 12GB: Index usage analysis reveals 8 indexes with zero scans over 30 days, totaling 12GB of storage. After confirming none are used for FK enforcement or unique constraints, dropping them reduces write latency by 18% and frees disk space. Command: DROP INDEX CONCURRENTLY idx_name.

Replacing 3 single-column indexes with 1 composite covering index: Table has separate indexes on (user_id), (created_at), and (status). Most queries filter on all three. A single composite index (user_id, status, created_at) INCLUDE (amount) replaces all three, reduces total index storage by 40%, and enables index-only scans for the dashboard query.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.99%
按下载量换算85

Claude

30.45%
按下载量换算76

Cursor

16.99%
按下载量换算42

Gemini CLI

10.32%
按下载量换算26

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills