Agent skill

Optimizing Query Text

by AltimateAI in AltimateAI/data-engineering-skills

Optimizes Snowflake SQL query performance from provided query text.

MITAuto-check passedDatabases

Install Optimizing Query Text

skills CLI
$ npx skills add AltimateAI/data-engineering-skills --skill optimizing-query-text -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install AltimateAI/data-engineering-skills optimizing-query-text --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/AltimateAI/data-engineering-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/snowflake/optimizing-query-text .claude/skills/optimizing-query-text && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
optimizing-query-text
GitHub stars
127
Token cost
~1.7k tokens
SKILL.md length
812 words
Files
1
Skills in repo
12
Repo updated
First seen
Licence
MIT

At a glance

Optimizes Snowflake SQL query performance from provided query text.

  • Works in 4 steps: Minimal changes: Make the fewest changes… → Preserve structure: Keep subqueries,… → When in doubt, don't: If unsure whether… → …
  • Optimizing Snowflake SQL for:
  • SKILL.md covers OUTPUT FORMAT, CRITICAL: Semantic…, Pattern 1: Function on Filter… and Pattern 2: Function on JOIN…, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Optimizing Query Text is an agent skill from AltimateAI/data-engineering-skills. Optimizes Snowflake SQL query performance from provided query text. Use when optimizing Snowflake SQL for: (1) User provides or pastes a SQL query and asks to optimize, tune, or improve it (2) Task mentions "slow query", "make faster", "improve performance", "optimize SQL", or "query tuning" (3) Reviewing SQL for performance anti-patterns (function on filter column, implicit joins, etc.) (4) User asks why a query is slow or how to speed it up

Its SKILL.md is about 1.7k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering SQL, Data warehousing and Query optimization. It works with SQL and Snowflake. The repository describes itself as: Skills related to Data Engineering Work for Claude Code. The licence is MIT.

When your agent uses it

  • Optimizing Snowflake SQL for:
  • Pastes a SQL query and asks to optimize
  • Task mentions slow query
  • Improve performance

Example prompts

  • “slow query”
  • “make faster”
  • “improve performance”
  • “/optimizing-query-text”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  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.

What it can do on your machine

Read from SKILL.md and the folder at commit 705c68b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Optimizing Query Text loads about 1.7k tokens when it runs. Until then it costs about 117 tokens; SKILL.md has 812 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~117
When it runs · the whole SKILL.md, loaded when a task matches
~1.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from AltimateAI/data-engineering-skills at commit 705c68b, republished under its MIT licence (© AltimateAI). 812 words, ~1,679 tokens.

Download SKILL.mdSave it as .claude/skills/optimizing-query-text/SKILL.md (or your agent's skills folder).
name
optimizing-query-text
description
Optimizes Snowflake SQL query performance from provided query text. Use when optimizing Snowflake SQL for: (1) User provides or pastes a SQL query and asks to optimize, tune, or improve it (2) Task mentions "slow query", "make faster", "improve performance", "optimize SQL", or "query tuning" (3) Reviewing SQL for performance anti-patterns (function on filter column, implicit joins, etc.) (4) User asks why a query is slow or how to speed it up

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.


Show full SKILL.md (312 more words)Show less

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

© AltimateAI, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/snowflake/optimizing-query-text of AltimateAI/data-engineering-skills.

Open the folder on GitHubat commit 705c68b

Compare with similar skills

Optimizing Query Text next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Optimizing Query Text compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Optimizing Query Text this skillAltimateAI/data-engineering-skills127—~1.7kAutomated safety check: PassMIT
Snowflake Developmentsickn33/agentic-awesome-skills47k2 repos~2.1kAutomated safety check: PassMIT
Snowflake Developmentalirezarezvani/claude-skills28k—~3.2kAutomated safety check: PassMIT
Uipath Process MiningUiPath/skills166—~4.3kAutomated safety check: NotesMIT
Snowflake Data EngineeringMindrally/skills267—~2.3kAutomated safety check: PassApache-2.0
Analyzing Dataastronomer/agents450—~1.3kAutomated safety check: PassApache-2.0

Similar skills

  • Snowflake Development

    sickn33/agentic-awesome-skills

    Comprehensive Snowflake development assistant covering SQL best practices, data pipeline design (Dynamic Tables, Streams, Tasks, Snowpipe), Cortex AI functions, Cortex Agents, Snowpark Python, dbt…

    47k GitHub starsUsed in 2 repos~2.1k tokens
    DatabasesAuto-check passed
  • Snowflake Development

    alirezarezvani/claude-skills

    A skill your agent uses when writing Snowflake SQL, building data pipelines with Dynamic Tables or Streams/Tasks, using Cortex AI functions, creating Cortex Agents, writing Snowpark Python…

    28k GitHub stars~3.2k tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • UiPath Process Mining via uip pm — build and operate a process app end-to-end from a CSV / event log: templates, data mapping, upload, ingest, the dbt (Snowflake) transformation layer, publish, and…

    166 GitHub stars~4.3k tokensUpdated today
    DatabasesAuto-check: notes
  • Best practices for Snowflake SQL, semi-structured data, and data pipelines built with Dynamic Tables, Streams, Tasks, and Snowpipe.

    267 GitHub stars~2.3k tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • Analyzing Data

    astronomer/agents

    Queries the data warehouse with SQL and answers business questions about data.

    450 GitHub stars~1.3k tokensUpdated 2 days ago
    DatabasesAuto-check passed
  • Modeler

    sidequery/sidemantic

    Build, validate, and manage semantic models using Sidemantic.

    129 GitHub stars~4.2k tokensUpdated today
    DatabasesAuto-check passed

More from AltimateAI/data-engineering-skills

All 12 skills in this repo
  • Altimate Data Warehouse Delegate

    AltimateAI/data-engineering-skills

    Delegates dbt and warehouse tasks such as lineage, migrations and cost attribution to the altimate-code CLI agent and relays its answer back.

    127 GitHub stars~1.4k tokensUpdated 5 days ago
    Auto-check passed
  • dbt Model Builder

    AltimateAI/data-engineering-skills

    Creates or modifies dbt models in line with a project's own conventions, then runs dbt build and dbt show to check the output instead of stopping at compile.

    127 GitHub stars~890 tokensUpdated 5 days ago
    Auto-check passed
  • dbt Error Debugging

    AltimateAI/data-engineering-skills

    Walks through fixing dbt compilation, database and test errors: read the full error, check upstream models, apply a fix, then verify with dbt build and a data preview.

    127 GitHub stars~1.1k tokensUpdated 5 days ago
    Auto-check passed
  • dbt Incremental Models

    AltimateAI/data-engineering-skills

    Helps choose an incremental strategy, design a reliable unique_key and debug failing dbt incremental models, and says when a plain table is the better choice.

    127 GitHub stars~2.3k tokensUpdated 5 days ago
    Auto-check passed
  • dbt Model Documentation

    AltimateAI/data-engineering-skills

    Writes model and column descriptions in dbt schema.yml files, matching the project's existing documentation style and recording grain, business rules and caveats.

    127 GitHub stars~1.2k tokensUpdated 5 days ago
    Auto-check passed
  • Expensive Snowflake Query Finder

    AltimateAI/data-engineering-skills

    Ranks the costliest, slowest or heaviest-scanning Snowflake queries from query history and suggests how to optimize them.

    127 GitHub stars~662 tokensUpdated 5 days ago
    Auto-check passed

Works with

Categories

Questions about Optimizing Query Text

What does Optimizing Query Text do?

Optimizes Snowflake SQL query performance from provided query text. Optimizing Query Text is an agent skill from AltimateAI/data-engineering-skills. Optimizes Snowflake SQL query performance from provided query text.

When should I use Optimizing Query Text?

Optimizing Query Text fits situations like: optimizing Snowflake SQL for:; pastes a SQL query and asks to optimize; task mentions slow query; improve performance.

How do I install Optimizing Query Text in Claude Code?

Run `npx skills add AltimateAI/data-engineering-skills --skill optimizing-query-text -a claude-code`. Or copy the skill folder (skills/snowflake/optimizing-query-text in AltimateAI/data-engineering-skills) into .claude/skills/optimizing-query-text in your project. Claude Code loads it when a task matches its description.

How do I install Optimizing Query Text in Codex?

Run `npx skills add AltimateAI/data-engineering-skills --skill optimizing-query-text -a codex`. Or copy the skill folder (skills/snowflake/optimizing-query-text in AltimateAI/data-engineering-skills) into .agents/skills/optimizing-query-text in your project. Codex loads it when a task matches its description.

Can I use Optimizing Query Text in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add AltimateAI/data-engineering-skills --skill optimizing-query-text -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/optimizing-query-text, .gemini/skills/optimizing-query-text, .github/skills/optimizing-query-text and .opencode/skills/optimizing-query-text in your project.

What does Optimizing Query Text need to run?

SKILL.md names no scripts, command-line tools or credentials: Optimizing Query Text is instructions for the agent only.

Does Optimizing Query Text access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Optimizing Query Text safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Optimizing Query Text use?

Optimizing Query Text is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Optimizing Query Text use?

About 1.7k tokens (SKILL.md is roughly 6.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Optimizing Query Text?

Skills that share tags, products or a category with Optimizing Query Text: Snowflake Development (sickn33/agentic-awesome-skills, 47k stars), Snowflake Development (alirezarezvani/claude-skills, 28k stars), Uipath Process Mining (UiPath/skills, 166 stars) and Snowflake Data Engineering (Mindrally/skills, 267 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Optimizing Query Text?

AltimateAI (a GitHub organization) maintains it in AltimateAI/data-engineering-skills, which has 127 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 1, 2026.

Source: AltimateAI/data-engineering-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.