← 返回 Skill 列表
extension
分类: 开发与工程API Key 暂未确认

SQL-Query-Optimizer

Analyze SQL queries, execution plans, and table schemas to identify performance bottlenecks and recommend safe SQL rewrites and indexing improvements. Use when diagnosing slow queries or optimizing database workloads.

person作者: wuzekaihubModelScope

SQL Query Optimizer

Overview

This skill helps developers analyze and optimize SQL queries for relational databases, including OceanBase and MySQL-compatible systems.

When to Use

Use this skill when a user:

  • Reports a slow SQL query.
  • Provides an SQL execution plan for analysis.
  • Wants recommendations for indexing.
  • Needs help rewriting a query for better performance.

Workflow

Step 1: Collect Context

Request the SQL statement, database version, relevant table schemas, existing indexes, and execution plan when available.

Do not assume missing schema or statistics.

Step 2: Analyze the Query

Identify potential performance bottlenecks:

  • Full table scans on large tables.
  • Expensive joins or subqueries.
  • Missing or ineffective indexes.
  • Unnecessary sorting or aggregation.
  • Large intermediate results.
  • Inaccurate cardinality estimates.

Distinguish observations supported by the execution plan from hypotheses requiring verification.

Step 3: Recommend Optimizations

Suggest improvements in priority order:

  1. SQL rewriting without changing query semantics.
  2. Appropriate indexes based on filters and joins.
  3. Reducing unnecessary intermediate data.
  4. Checking database statistics and execution plans.

Explain trade-offs, including index storage and write overhead.

Step 4: Validate

Recommend comparing before-and-after execution plans, latency, and resource usage.

Do not claim a performance improvement without benchmark evidence.

Output Format

Provide:

  1. Bottleneck analysis.
  2. Recommended SQL rewrite, if applicable.
  3. Index recommendations.
  4. Expected benefits and trade-offs.
  5. Steps to validate performance.

Safety

Never execute destructive SQL statements or change production schemas without explicit user approval. Preserve the original query semantics. Do not invent benchmark measurements.

Example

Input: SELECT * FROM orders WHERE customer_id = 100;

Possible recommendation: Check whether an index on orders(customer_id) exists and whether the execution plan uses it. Evaluate its benefit against the table size and query selectivity.

<!-- OB-S:DbcfB4EuftvToa3U6mrKfQ -->