sql-optimization
Skill138 starsChanged 6 months agoMITView on GitHub
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".
7 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- github/awesome-copilotedited, first seen Sep 23, 2026
- jgamaraalv/delivery-looptheir own version, first seen Jul 4, 2026
- bmsuisse/skillstheir own version, first seen Apr 21, 2026
- iCesofT/awesome-aitheir own version, first seen Apr 16, 2026
- snickerjp/Agent-Skillsedited, first seen Mar 28, 2026
- Ryanb58/agentskillstheir own version, first seen Feb 22, 2026
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 2
- github/awesome-copilot★ 40k23% same
- snickerjp/Agent-Skills★ 023% same
Wrote their own version · 5
- stefan-jansen/claude-code-toolkit★ 87same name
- jgamaraalv/delivery-loop★ 4same name
- bmsuisse/skills★ 2same name
- iCesofT/awesome-ai★ 1same name
- Ryanb58/agentskills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- instructions/AGENTS.mdAGENTS.md
- instructions/CLAUDE.mdCLAUDE.md
- advpl-tlpp-compileSkill
- advpl-tlpp-sddSkill
- advpl-to-tlpp-migrationSkill
- code-reviewSkill
- context-mapSkill
- create-implementation-planSkill
- data-dictionary-lookupSkill
- documentation-writerSkill
- entry-point-designerSkill
- fwmsexcelxlsx-generatorSkill
- fwrest-client-generatorSkill
- mvc-generatorSkill
- query-builderSkill
- refactor-method-complexity-reduceSkill
- refactorSkill
- sql-code-reviewSkill
- tir-test-generatorSkill
- tlpp-rest-endpoint-generatorSkill
- utf8-to-cp1252-conversionSkill
- brainstormingSkill
- dispatching-parallel-agentsSkill
- executing-plansSkill
- finishing-a-development-branchSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- writing-plansSkill
- writing-skillsSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 61
Identify: Use database-specific tools to find slow queries
- Distinctive: line 64
Test: Verify performance improvements
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Identify: Use database-specific tools to find slow queries
- Analyze: Examine execution plans and identify bottlenecks
- Optimize: Apply appropriate optimization techniques
- Test: Verify performance improvements
- Monitor: Continuously track performance metrics
- 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 selectedD_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,TCQueryorTCSqlExeccalls inside loops — batch with:SetIn()or a single statement - Temporary aliases opened by
FWExecStatement:OpenAlias()(or legacyTCQuery ... 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
FWExecStatementis used when user input is part of the query- Index usage verified against SIX dictionary entries
- No
IIF()in SQL construction — useCASE WHENorIf/Else/EndIfin AdvPL logic
Refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

