Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计异常

optimizing-query-text优化查询文本

Agent Skill

optimizing-query-text 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

233

周安装

10

GitHub Stars

90

下载量

82
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/altimateai/data-engineering-skills --skill optimizing-query-text

简介

针对文本字段查询进行性能调优与全文检索增强。

  • 支持模糊匹配、分词策略和全文索引配置建议。
  • 可识别低效 LIKE 操作并提供替代方案如 FTS(Full-Text Search)。
  • 使用前需确认数据库是否支持高级文本搜索功能及其版本兼容性。
  • optimizing-query-text 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Optimize Query from SQL Text

OUTPUT FORMAT

Return ONLY the optimized SQL query. No markdown formatting, no explanations, no bullet points - just pure SQL that can be executed directly in Snowflake.

CRITICAL: Semantic Preservation Rules

The optimized query MUST return IDENTICAL results to the original.

Before returning ANY optimization, verify:

  • Same columns: Exact same columns in exact same order with exact same aliases
  • Same rows: Filter conditions must be semantically equivalent
  • Same ordering: Preserve ORDER BY exactly as written
  • Same limits: If original has LIMIT N, keep LIMIT N. If no LIMIT, do NOT add one.

If you cannot guarantee identical results, return the original query unchanged.


Pattern 1: Function on Filter Column

Problem: Functions on columns in WHERE clause prevent partition pruning and index usage.

CAN Fix

OriginalOptimizedWhy Safe
WHERE DATE(ts) = '2024-01-01'WHERE ts >= '2024-01-01' AND ts < '2024-01-02'Equivalent range
WHERE YEAR(dt) = 2024WHERE dt >= '2024-01-01' AND dt < '2025-01-01'Equivalent range
WHERE MONTH(dt) = 3 AND YEAR(dt) = 2024WHERE dt >= '2024-03-01' AND dt < '2024-04-01'Equivalent range
WHERE DATE(ts) >= '2024-01-01' AND DATE(ts) < '2024-02-01'WHERE ts >= '2024-01-01' AND ts < '2024-02-01'Same boundaries
WHERE YEAR(dt) BETWEEN 1995 AND 1996WHERE dt >= '1995-01-01' AND dt < '1997-01-01'Equivalent range

CANNOT Fix

PatternWhy Not
WHERE YEAR(dt) IN (SELECT year FROM...)Dynamic values, cannot precompute range
WHERE DATE(ts) = DATE(other_col)Comparing two columns, both need function
WHERE EXTRACT(DOW FROM dt) = 1Day-of-week has no contiguous range
WHERE DATE_TRUNC('month', dt) = '2024-01-01' in GROUP BYNeeded for grouping logic
SELECT YEAR(dt) AS yr... GROUP BY YEAR(dt)Function in SELECT/GROUP BY is fine, only filter matters

Pattern 2: Function on JOIN Column

Problem: Functions on JOIN columns prevent hash joins, forcing slower nested loop joins.

CAN Fix

OriginalOptimizedWhy Safe
ON CAST(a.id AS VARCHAR) = CAST(b.id AS VARCHAR)ON a.id = b.idIf both are same type (e.g., INTEGER)
ON UPPER(a.code) = UPPER(b.code)ON a.code = b.codeIf data is already consistently cased
ON TRIM(a.name) = TRIM(b.name)ON a.name = b.nameIf data has no leading/trailing spaces

CANNOT Fix

PatternWhy Not
ON CAST(a.id AS VARCHAR) = b.string_idTypes genuinely differ, CAST required
ON DATE(a.timestamp) = b.date_colDifferent granularity, DATE() required
ON UPPER(a.code) = b.codeIf b.code might have different case
ON a.id = b.id + 1Arithmetic transformation, cannot remove

Pattern 3: NOT IN Subquery

Problem: NOT IN has poor performance and unexpected NULL behavior.

CAN Fix

OriginalOptimizedWhy Safe
WHERE id NOT IN (SELECT id FROM t WHERE...)WHERE NOT EXISTS (SELECT 1 FROM t WHERE t.id = main.id AND...)Equivalent when subquery column is NOT NULL
WHERE id NOT IN (SELECT id FROM t) where id has NOT NULL constraintWHERE NOT EXISTS (SELECT 1 FROM t WHERE t.id = main.id)NOT NULL guarantees equivalence

CANNOT Fix

PatternWhy Not
WHERE id NOT IN (SELECT nullable_col FROM t)If subquery returns NULL, NOT IN returns no rows; NOT EXISTS doesn't
WHERE (a, b) NOT IN (SELECT x, y FROM t)Multi-column NOT IN has complex NULL semantics

Key Rule: Only convert NOT IN to NOT EXISTS if you can verify the subquery column cannot be NULL.


Pattern 4: Repeated Subquery

Problem: Same subquery executed multiple times causes redundant scans.

CAN Fix

OriginalOptimized
Subquery appears 2+ times identicallyExtract to CTE, reference CTE multiple times
Same aggregation used in multiple placesCompute once in CTE

CANNOT Fix

PatternWhy Not
Correlated subquery (references outer table)Each execution is different, cannot cache
Subqueries with different filtersNot actually the same subquery
Subquery in SELECT that depends on current rowCorrelation prevents extraction

Pattern 5: Implicit Comma Joins

Problem: Comma-separated tables in FROM clause are harder to read and optimize.

CAN Fix - Always

Convert FROM a, b, c WHERE a.id = b.id AND b.id = c.id to explicit JOIN syntax.

This is always safe - just restructuring, no semantic change.


UNSAFE Optimizations (NEVER apply)

  • UNION to UNION ALL: UNION deduplicates rows, UNION ALL does not - different results
  • Changing window functions: Do not modify SUM(SUM(x)) OVER(...) or similar nested aggregates
  • Adding redundant filters: Do not add filters in JOIN ON if same filter exists in WHERE
  • Changing column names: Copy column names EXACTLY from original - do not "simplify" or rename
  • Changing column aliases: Keep all aliases exactly as original
  • Adding early filtering in JOINs: If a filter is in WHERE, do not duplicate it in JOIN ON clause

Principles

  1. Minimal changes: Make the fewest changes necessary. Simpler optimizations are more reliable.
  2. Preserve structure: Keep subqueries, CTEs, and overall query structure unless there's a clear benefit.
  3. When in doubt, don't: If unsure whether a change preserves semantics, skip it.
  4. Copy exactly: Column names, table aliases, and expressions should be copied character-for-character.

Priority Order

  1. Date/time functions on filter columns - Highest impact
  2. Implicit joins to explicit JOIN - Always safe, improves readability
  3. NOT IN to NOT EXISTS - Only if NULL-safe

Requirements

  • Results must be identical: Same rows, same columns, same order
  • Valid Snowflake SQL: Output must execute without errors in Snowflake

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

34.29%
按下载量换算28

Claude

30.83%
按下载量换算25

Cursor

19.86%
按下载量换算16

Gemini CLI

10.25%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

只读

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

安装前确认

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

来源信息

继续浏览同类 Skills