Agent skill

SQL Optimization

by totvs in totvs/engpro-advpl-tlpp-skills

Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle).

MITAuto-check passedDatabases

Install SQL Optimization

skills CLI
$ npx skills add totvs/engpro-advpl-tlpp-skills --skill sql-optimization -a claude-code

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

GitHub CLI
$ gh skill install totvs/engpro-advpl-tlpp-skills sql-optimization --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/totvs/engpro-advpl-tlpp-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/advpl-tlpp/sql-optimization .claude/skills/sql-optimization && 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
sql-optimization
GitHub stars
143
Token cost
~1.2k tokens
SKILL.md length
487 words
Files
3 (incl. references)
Skills in repo
19
Repo updated
First seen
Licence
MIT

At a glance

Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle).

  • Works in 6 steps: Identify: Use database-specific tools to… → Analyze: Examine execution plans and… → Optimize: Apply appropriate optimization… → …
  • User says optimize SQL
  • SKILL.md covers Core Optimization Areas, Universal Optimization Checklist, 📝 Optimization Methodology and Protheus SQL Optimization
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

SQL Optimization is an agent skill from totvs/engpro-advpl-tlpp-skills. Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle). Provides execution plan analysis, pagination optimization, batch operations, and performance monitoring guidance. Use when user says "optimize SQL", "slow query", "index strategy", "execution plan analysis".

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files, including reference files (for example `references/sql-optimization-patterns.md` and `references/sql-optimization.md`).

It sits in Databases, covering SQL, Query optimization and Performance optimization. It works with SQL, Microsoft SQL Server and PostgreSQL. The repository describes itself as: Repositório contendo skills para orientar desenvolvimento ADVPL/TLPP com agentes de IA. The licence is MIT.

When your agent uses it

  • User says optimize SQL
  • Execution plan analysis

Example prompts

  • “optimize SQL”
  • “slow query”
  • “index strategy”
  • “/sql-optimization”

Workflow steps

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

  1. Identify: Use database-specific tools to find slow queries
  2. Analyze: Examine execution plans and identify bottlenecks
  3. Optimize: Apply appropriate optimization techniques
  4. Test: Verify performance improvements
  5. Monitor: Continuously track performance metrics
  6. Iterate: Regular performance review and optimization

What it can do on your machine

Read from SKILL.md and the folder at commit 3908e4e. 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

SQL Optimization loads about 1.2k tokens when it runs, and up to ~4.5k if it reads all its reference files. Until then it costs about 104 tokens; SKILL.md has 487 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~104
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~4.5k

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 totvs/engpro-advpl-tlpp-skills at commit 3908e4e, republished under its MIT licence (© totvs). 487 words, ~1,219 tokens.

Download SKILL.mdSave it as .claude/skills/sql-optimization/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
sql-optimization
description
Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle). Provides execution plan analysis, pagination optimization, batch operations, and performance monitoring guidance. Use when user says "optimize SQL", "slow query", "index strategy", "execution plan analysis".
license
MIT
metadata.domain
Protheus
metadata.maintainer
Customizações ADVPL/TLPP
metadata.author
Thalion Starforge
metadata.version
4.2.0
metadata.category
Code Quality and Review

SQL Performance Optimization Assistant

Expert SQL performance optimization for ${selection} (or entire project if no selection). Focus on universal SQL optimization techniques that work across PostgreSQL, SQL Server, Oracle, and other SQL databases.

Core Optimization Areas

This skill covers query performance analysis, index strategy, subquery optimization, JOIN optimization, pagination, aggregation, query anti-patterns, batch operations, temporary tables, index management, and performance monitoring.

For all universal SQL optimization patterns with BAD/GOOD code examples, see sql-optimization-patterns.md.

Universal Optimization Checklist

Query Structure
  • Avoiding SELECT * in production queries
  • Using appropriate JOIN types (INNER vs LEFT/RIGHT)
  • Filtering early in WHERE clauses
  • Using EXISTS instead of IN for subqueries when appropriate
  • Avoiding functions in WHERE clauses that prevent index usage
Index Strategy
  • Creating indexes on frequently queried columns
  • Using composite indexes in the right column order
  • Avoiding over-indexing (impacts INSERT/UPDATE performance)
  • Using covering indexes where beneficial
  • Creating partial indexes for specific query patterns
Data Types and Schema
  • Using appropriate data types for storage efficiency
  • Normalizing appropriately (3NF for OLTP, denormalized for OLAP)
  • Using constraints to help query optimizer
  • Partitioning large tables when appropriate
Query Patterns
  • Using LIMIT/TOP for result set control
  • Implementing efficient pagination strategies
  • Using batch operations for bulk data changes
  • Avoiding N+1 query problems
  • Using prepared statements for repeated queries
Performance Testing
  • Testing queries with realistic data volumes
  • Analyzing query execution plans
  • Monitoring query performance over time
  • Setting up alerts for slow queries
  • Regular index usage analysis

📝 Optimization Methodology

  1. Identify: Use database-specific tools to find slow queries
  2. Analyze: Examine execution plans and identify bottlenecks
  3. Optimize: Apply appropriate optimization techniques
  4. Test: Verify performance improvements
  5. Monitor: Continuously track performance metrics
  6. Iterate: Regular performance review and optimization

Focus on measurable performance improvements and always test optimizations with realistic data volumes and query patterns.


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

Protheus SQL Optimization

The TOTVS Protheus ERP has specific database access patterns and constraints that require targeted optimization strategies. This covers cross-database compatibility, high-volume table optimization, SIX index alignment, NOLOCK hints, FWExecStatement/TCSqlExec performance (preferred over legacy TCQuery), and Workarea vs. Embedded SQL decision guidance.

For complete Protheus-specific optimization patterns, code examples, and the high-volume table reference, see sql-optimization.md.

Protheus-Specific Optimization Checklist
  • Queries on SD1/SD2/SE1/SE2/CT2 include branch filter and use indexed columns
  • SELECT * is not used — only necessary columns are selected
  • D_E_L_E_T_ = ' ' is present on every Protheus table query
  • Read-only queries use %nolock% hint (cross-DB safe — translates on MSSQL, ignored on PostgreSQL/Oracle)
  • No FWExecStatement, TCQuery or TCSqlExec calls inside loops — batch with :SetIn() or a single statement
  • Temporary aliases opened by FWExecStatement:OpenAlias() (or legacy TCQuery ... New Alias) are closed after use and :Destroy() is called
  • RetSqlName() is used instead of hardcoded table names (e.g., SA1010)
  • Complex reports use SQL with proper JOINs instead of nested workarea loops
  • FWExecStatement is used when user input is part of the query
  • Index usage verified against SIX dictionary entries
  • No IIF() in SQL construction — use CASE WHEN or If/Else/EndIf in AdvPL logic

Refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference.

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

Files

SKILL.md and 2 other files (references) in skills/advpl-tlpp/sql-optimization of totvs/engpro-advpl-tlpp-skills.

  • SKILL.md
  • references/sql-optimization-patterns.md
  • references/sql-optimization.md

Open the folder on GitHubat commit 3908e4e

Compare with similar skills

SQL Optimization 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.

SQL Optimization compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL Optimization this skilltotvs/engpro-advpl-tlpp-skills143—~1.2kAutomated safety check: PassMIT
SQL Optimizationgithub/awesome-copilot40k2 repos~2.3kAutomated safety check: PassMIT
SQL ProJeffallan/claude-skills12k—~1.3kAutomated safety check: PassMIT
Optimizing SQLancoleman/ai-design-components526—~3kAutomated safety check: PassMIT
Agent SQL Proxiaoyuge886/aigc198—~315Automated safety check: PassMIT
SQL Expertaiskillstore/marketplace430—~3.4kAutomated safety check: PassNone

Similar skills

  • SQL Optimization

    github/awesome-copilot

    Official

    Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server…

    40k GitHub starsUsed in 2 repos~2.3k tokens
    DatabasesAuto-check passed
  • SQL Pro

    Jeffallan/claude-skills

    Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.

    12k GitHub stars~1.3k tokensUpdated 5 days ago
    DatabasesAuto-check passed
  • Optimizing SQL

    ancoleman/ai-design-components

    Optimize SQL query performance through EXPLAIN analysis, indexing strategies, and query rewriting for PostgreSQL, MySQL, and SQL Server.

    526 GitHub stars~3k tokensUpdated 10 mo ago
    DatabasesAuto-check passed
  • Agent SQL Pro

    xiaoyuge886/aigc

    Expert SQL developer specializing in complex query optimization, database design, and performance tuning across PostgreSQL, MySQL, SQL Server, and Oracle.

    198 GitHub stars~315 tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • SQL Expert

    aiskillstore/marketplace

    Expert SQL query writing, optimization, and database schema design with support for PostgreSQL, MySQL, SQLite, and SQL Server.

    430 GitHub stars~3.4k tokensUpdated yesterday
    DatabasesAuto-check passed
  • PostgreSQL Documentation Reference

    2025Emma/vibe-coding-cn

    PostgreSQL database documentation - SQL queries, database design, administration, performance tuning, and advanced features. Use when working with PostgreSQL…

    23k GitHub starsUsed in 1 repo~19k tokens
    DatabasesAuto-check passed

More from totvs/engpro-advpl-tlpp-skills

All 19 skills in this repo
  • AdvPL UTF-8 to CP1252 Converter

    totvs/engpro-advpl-tlpp-skills

    Converts AdvPL and TLPP source files from UTF-8 to Windows-1252 in place after code generation, because the Protheus compiler accepts only CP1252 files.

    143 GitHub stars~2.6k tokensUpdated 3 days ago
    Auto-check passed
  • AdvPL/TLPP Compile in VS Code

    totvs/engpro-advpl-tlpp-skills

    Compiles AdvPL and TLPP sources from VS Code with the TOTVS Developer Studio extension, handling server setup, connection and compile result reporting.

    143 GitHub stars~3.7k tokensUpdated 3 days ago
    Auto-check passed
  • Protheus Spec-Driven Development

    totvs/engpro-advpl-tlpp-skills

    Plans and builds Protheus AdvPL/TLPP features through Specify, Design, Tasks and Execute phases whose depth scales with the size of the change.

    143 GitHub stars~3.6k tokensUpdated 3 days ago
    Auto-check passed
  • AdvPL and TLPP Code Review

    totvs/engpro-advpl-tlpp-skills

    Reviews AdvPL and TLPP source against SonarQube rules, ProtheusDOC requirements, security, performance and Protheus conventions, and reports findings by severity.

    143 GitHub stars~2.5k tokensUpdated 3 days ago
    Auto-check passed
  • Protheus Data Dictionary Lookup

    totvs/engpro-advpl-tlpp-skills

    Queries the TOTVS Protheus ERP data dictionary for tables, fields, indexes, parameters, triggers and lookups, including impact checks during refactoring.

    143 GitHub stars~1.5k tokensUpdated 3 days ago
    Auto-check passed
  • Protheus MVC Generator

    totvs/engpro-advpl-tlpp-skills

    Generates Protheus MVC screens in ADVPL/TLPP, with ModelDef, ViewDef, MenuDef and Browse functions for single-entity and master-detail layouts.

    143 GitHub stars~2.2k tokensUpdated 3 days ago
    Auto-check passed

Categories

Questions about SQL Optimization

What does SQL Optimization do?

Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle). SQL Optimization is an agent skill from totvs/engpro-advpl-tlpp-skills. Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across SQL databases (PostgreSQL, SQL Server, Oracle).

When should I use SQL Optimization?

SQL Optimization fits situations like: user says optimize SQL; execution plan analysis.

How do I install SQL Optimization in Claude Code?

Run `npx skills add totvs/engpro-advpl-tlpp-skills --skill sql-optimization -a claude-code`. Or copy the skill folder (skills/advpl-tlpp/sql-optimization in totvs/engpro-advpl-tlpp-skills) into .claude/skills/sql-optimization in your project. Claude Code loads it when a task matches its description.

How do I install SQL Optimization in Codex?

Run `npx skills add totvs/engpro-advpl-tlpp-skills --skill sql-optimization -a codex`. Or copy the skill folder (skills/advpl-tlpp/sql-optimization in totvs/engpro-advpl-tlpp-skills) into .agents/skills/sql-optimization in your project. Codex loads it when a task matches its description.

Can I use SQL Optimization 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 totvs/engpro-advpl-tlpp-skills --skill sql-optimization -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-optimization, .gemini/skills/sql-optimization, .github/skills/sql-optimization and .opencode/skills/sql-optimization in your project.

What does SQL Optimization need to run?

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

Does SQL Optimization 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 SQL Optimization 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 SQL Optimization use?

SQL Optimization is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL Optimization use?

About 1.2k tokens (SKILL.md is roughly 4.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 3.3k tokens, read only when the agent opens those files.

What are the alternatives to SQL Optimization?

Skills that share tags, products or a category with SQL Optimization: SQL Optimization (github/awesome-copilot, 40k stars), SQL Pro (Jeffallan/claude-skills, 12k stars), Optimizing SQL (ancoleman/ai-design-components, 526 stars) and Agent SQL Pro (xiaoyuge886/aigc, 198 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL Optimization?

totvs (a GitHub organization) maintains it in totvs/engpro-advpl-tlpp-skills, which has 143 GitHub stars. The repository holds 19 skills in this directory. The repository was last updated on October 5, 2026.

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