Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问clear审计通过

query-optimize查询优化

Agent Skill

query-optimize 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

857

周安装

35

GitHub Stars

93

下载量

277
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:query-optimize(查询优化)
来源仓库:https://github.com/letta-ai/skills
仓库路径:skills/query-optimize
安装命令:
npx skills add https://github.com/letta-ai/skills --skill query-optimize
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/letta-ai/skills --skill query-optimize

简介

用于查找、检索和筛选相关信息,支持关键词快速定位候选结果。

  • 适合在开发过程中根据任务场景或来源线索获取技术资料。
  • 可结合仓库 README 核验具体用法,提升信息检索效率。
  • 安装前建议确认权限范围和维护状态,避免触发不必要的网络或文件操作。
  • 适用于 Codex、Claude、Cursor 等主流 AI 宿主环境。

SKILL.md

SQL Query Optimization

This skill provides procedural guidance for optimizing SQL queries effectively, with emphasis on proper benchmarking, query plan analysis, and iterative refinement.

Core Optimization Workflow

1. Establish Performance Baselines

Before making any changes, establish clear performance metrics:

  • Identify the target: Determine what "optimal" performance looks like. Look for reference implementations, documented benchmarks, or theoretical analysis of query complexity.
  • Measure the original query: Record execution time with multiple runs to account for caching effects.
  • Document the goal: Define success as "as fast as possible" not just "faster than the original."

2. Analyze Query Plans

Always use query plan analysis before and after optimization:

-- SQLite
EXPLAIN QUERY PLAN <query>;

-- PostgreSQL
EXPLAIN ANALYZE <query>;

-- MySQL
EXPLAIN <query>;

Key indicators to look for in query plans:

  • Full table scans (SCAN TABLE) vs index usage (SEARCH TABLE USING INDEX)
  • Correlated subqueries executing per-row
  • Temporary B-tree creation for sorting/grouping
  • Materialization of intermediate results
  • Join order and join types

3. Identify Common Performance Issues

Correlated Subqueries: Subqueries that reference outer query columns execute once per row. Transform to JOINs or CTEs when possible.

Repeated Computations: The same subquery appearing multiple times should be factored out into a CTE or subquery.

Missing Indexes: Check for indexes on columns used in WHERE, JOIN, and ORDER BY clauses.

Inefficient Aggregations: GROUP BY on large result sets before filtering. Consider filtering earlier with WHERE.

4. Apply Optimization Techniques

Consider multiple approaches rather than stopping at the first working solution:

Approach 1: CTEs (Common Table Expressions)

  • Pre-compute values used multiple times
  • Improve readability
  • Note: Some databases materialize CTEs which may hurt performance

Approach 2: Window Functions

  • Efficient for ranking, running totals, and row numbering
  • Avoid when simpler alternatives exist

Approach 3: Subquery Restructuring

  • Convert correlated subqueries to JOINs
  • Push predicates into subqueries to reduce intermediate result sizes

Approach 4: Join Optimization

  • Reorder joins to filter early
  • Use appropriate join types (INNER vs LEFT)
  • Consider join hints if available

5. Database-Specific Considerations

SQLite:

  • No parallel query execution
  • CTEs may be materialized (can hurt performance)
  • Limited optimizer compared to enterprise databases
  • Consider using covering indexes

PostgreSQL:

  • Supports parallel execution
  • Advanced optimizer with cost-based decisions
  • CTEs are optimization barriers in older versions (< 12)

MySQL:

  • Derived table materialization can be forced or avoided
  • Index hints available when optimizer makes poor choices

Verification Strategy

Correctness Verification

  1. Full result comparison: Compare all rows and columns against the original query output
  2. Edge case testing: Test with NULL values, empty results, ties in sorting/ranking
  3. Sample verification is insufficient: If the full result set is too large, use checksums or row counts with spot checks

Performance Verification

  1. Multiple runs: Execute at least 3-5 times and use median time
  2. Cold vs warm cache: Test both scenarios if relevant
  3. Compare against optimal: If a reference solution exists, compare against it, not just the original slow query
  4. Incremental profiling: Measure each CTE or subquery independently to identify bottlenecks

Common Pitfalls

Satisficing vs Optimizing

  • Problem: Stopping optimization when query is "faster than before" rather than "as fast as possible"
  • Prevention: Always establish what optimal performance looks like before starting. Compare against known-good implementations when available.

Skipping Query Plan Analysis

  • Problem: Making changes without understanding why the query is slow
  • Prevention: Always run EXPLAIN before and after changes. Understand the query plan before proposing solutions.

Premature CTE Usage

  • Problem: Assuming CTEs always improve performance. Some databases materialize CTEs, adding overhead.
  • Prevention: Test both CTE and non-CTE versions. Profile each CTE independently.

Over-reliance on Window Functions

  • Problem: Using ROW_NUMBER() or similar when simpler approaches work
  • Prevention: Consider if a GROUP BY with MIN/MAX or a simple correlated subquery might be more efficient.

Incomplete Testing

  • Problem: Verifying only a sample of rows due to timeouts
  • Prevention: Use checksums, row counts, or hash comparisons for full validation. Test with smaller data subsets first.

Single-Approach Optimization

  • Problem: Implementing one optimization approach without exploring alternatives
  • Prevention: Always test at least 2-3 different approaches before selecting the best one.

Iterative Refinement Process

  1. Analyze the original query and its plan
  2. Identify the primary bottleneck
  3. Propose 2-3 alternative approaches
  4. Implement and benchmark each approach
  5. Select the best performing approach
  6. Verify correctness with full result comparison
  7. Document the optimization rationale

Checklist Before Declaring Success

  • Query plan analyzed and understood
  • Multiple optimization approaches considered
  • Performance compared against optimal/reference (not just original)
  • Full result correctness verified (not just samples)
  • Edge cases tested (NULLs, ties, empty results)
  • Performance measured across multiple runs
  • Database-specific optimizations considered

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

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

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

平台分布

Claude Code

28.89%
按下载量换算80

Gemini CLI

21.83%
按下载量换算60

Codex

16.27%
按下载量换算45

Antigravity

12.34%
按下载量换算34

OpenCode

7.72%
按下载量换算21

windsurf

3.37%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills