agentsclimarketplace

Sql optimization

Skill tbc-servicos/dataagile-agent-kit/protheus/skills/sql-optimization

Plugin Claude Code para Protheus e ADVPL/TLPP — base 155k+ registros, Agent Teams, compilação TDS-CLI, testes TIR e MCP PO-UI

Install
npx -y skills add tbc-servicos/dataagile-agent-kit --skill sql-optimization

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

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".

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

4.8 KB, 951 tokens by cl100k_base, as published. Nobody here has run it

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.


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.

What ships with it: 2 files

12.8 KB alongside SKILL.md

Gives 0 of the 12 instructions most performance cost skills give in 951 tokens

Counted across 803 of the 1,058 authors here whose files we hold, read 2026-08-07

  • Keep skill files under 500 lines or tokensin 82 of 803, across 16 files
  • Use imperative form in instructionsin 80 of 803, across 9 files
  • Draft assertions while test runs are in progressin 75 of 803, across 9 files
  • Create two to three realistic test promptsin 74 of 803, across 9 files
  • Write skill descriptions to be pushyin 72 of 803, across 7 files
  • Save test cases to evals JSONin 72 of 803, across 6 files
  • Ask questions about edge cases and input formatsin 72 of 803, across 7 files
  • Save timing data immediately when runs completein 70 of 803, across 5 files
  • Include all trigger conditions in the skill descriptionin 69 of 803, across 3 files
  • Launch all test runs in a single turn or simultaneouslyin 69 of 803, across 3 files
  • Capture intent before writing a skillin 67 of 803, across 1 file
  • Import directly instead of barrel filesin 52 of 803, across 15 files

Said here and by no other author read

  • avoid SELECT * in production queries
  • filter early in WHERE clauses
  • use EXISTS instead of IN for subqueries
  • avoid over-indexing tables

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.