AgentSkillsCN

sql-indexing-patterns

设计并推荐 SQL Server 索引,包括覆盖索引、复合键策略、筛选索引、列存储索引,以及索引维护方案。分析缺失索引的 DMV、碎片化情况,以及 SARGability。提供索引命名规范、列排序规则,以及冗余检测方法。

SKILL.md
--- frontmatter
name: sql-indexing-patterns
description: Design and recommend SQL Server indexes including covering indexes, composite key strategies, filtered indexes, columnstore indexes, and index maintenance. Analyze missing index DMVs, fragmentation, and SARGability. Provides index naming conventions, column ordering rules, and redundancy detection.

SQL Server Indexing Patterns

This skill helps design optimal indexing strategies and analyze index usage for SQL Server workloads.

When to Use

  • Recommending indexes for slow queries
  • Reviewing existing index strategies
  • Analyzing missing index DMV output
  • Designing indexes for new tables or features
  • Checking index fragmentation and maintenance needs

Index Types

TypeBest ForExample
CoveringQueries selecting specific columns beyond the keyIX_Orders_Status INCLUDE (total_amount)
CompositeMulti-column WHERE/JOIN predicatesIX_Sales_Region_Date (region, sale_date)
FilteredQueries always filtering on a fixed predicateWHERE is_active = 1
ColumnstoreAnalytics, aggregation, data warehouse queriesCCI_SalesHistory

Column Ordering Rules

  1. Equality predicates first (=)
  2. Range predicates second (>, <, BETWEEN)
  3. ORDER BY columns third
  4. SELECT-only columns in INCLUDE

Reference Material

Detailed patterns, maintenance scripts, and missing index DMV queries: