sql-optimization

Analyze SQL execution plans and indexing strategies to reduce query latency.

115|54|Updated May 25, 2026
One-click install
npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill sql-optimization-totvs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimization
Source: https://github.com/totvs/engpro-advpl-tlpp-skills/tree/main/skills/advpl-tlpp/sql-optimization
Command: npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill sql-optimization-totvs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you diagnose and improve slow or inefficient SQL queries by applying cross-database performance best practices and validating changes with execution plan analysis.

Core Features & Use Cases

  • Universal query tuning: identify anti-patterns (like SELECT * and non-sargable predicates), improve JOIN/subquery structure, and optimize aggregation, pagination, and batching approaches.
  • Index strategy guidance: design appropriate composite/covering/partial indexes and align WHERE clause column order with available indexes (including Protheus SIX dictionary alignment).
  • Protheus/AdvPL-specific optimization: recommend the correct patterns for FWExecStatement/TCSqlExec usage, temporary tables, NOLOCK for read-only queries, and guidance on workarea vs embedded SQL choices.

Use cases include resolving “slow query” complaints, reducing full table scans, improving pagination performance, and refactoring Protheus SQL/AdvPL execution patterns for higher throughput.

Quick Start

Ask the agent to optimize your SQL by analyzing the execution plan, proposing index and query rewrites, and providing a Protheus-safe AdvPL guidance when applicable.

Frequently Asked Questions about sql-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow SQL queries and prevent full table scans?

To optimize slow SQL queries and prevent full table scans, analyze the execution plan and indexing strategy, rewrite non-sargable predicates, and align WHERE clause column order with composite or covering indexes.

What's the best way to improve slow pagination performance in PostgreSQL or SQL Server?

Improving slow pagination performance in PostgreSQL or SQL Server requires analyzing execution plans and applying keyset pagination or optimized batching approaches to reduce latency and avoid scanning unnecessary rows.

How do I tune Protheus ADVPL embedded SQL queries for better database performance?

Tuning Protheus ADVPL embedded SQL involves applying FWExecStatement and TCSqlExec batching patterns, using %nolock% for read-only queries, and aligning execution with the SIX dictionary and D_E_L_E_T_ usage rules.

Does query tuning work across PostgreSQL, SQL Server, and Oracle execution plans?

Yes, query tuning applies cross-database performance best practices across PostgreSQL, SQL Server, and Oracle by analyzing execution plans, improving JOIN and subquery structures, and optimizing aggregation approaches.

Why does my SQL query ignore the indexing strategy and run slow?

Your SQL query ignores the indexing strategy and runs slow when WHERE clause predicates are non-sargable, preventing index usage; refactoring query structure and aligning column order with available indexes resolves this.

When do I need to use NOLOCK or temporary tables in Protheus SQL execution?

You need to use %nolock% for read-only queries and temporary tables in Protheus SQL execution to improve throughput when processing batch operations, following FWExecStatement and TCSqlExec guidance.