Back to catalog / Agent workflows
Optimize slow SQL with execution-plan validation
Use analyzer, rewriter, and validator agents on a slow query; compare plans and cost estimates before delivering reviewable SQL.
Goal
Deliver a faster equivalent query and validation evidence in the SQLite warehouse simulation.
Steps
- Give the slow SQL and expected result fields to Analyzer Agent and retrieve its execution plan. [src10-strands-rewrite-slow-sql-with-execution-plan-validation]
- Have Rewriter Agent propose a rewrite, then compare original and candidate with get_query_execution_plan and validate_query_cost. [src10-strands-rewrite-slow-sql-with-execution-plan-validation]
- Keep only a candidate whose result fields/rows match and whose validator confirms improvement; include both SQL statements and plan differences. [src10-strands-rewrite-slow-sql-with-execution-plan-validation]
How to verify
On the same SQLite sample, confirm original and rewritten query results match and retain the plan/cost validation output.
Troubleshooting
If rows differ, reject the candidate and inspect joins or predicates; if cost validation fails, revisit the analyzer’s bottleneck rather than formatting alone.
Permissions
Prerequisites
- Python 3.10+, Strands sample dependencies, the SQLite demo database, and a slow-query sample.
Permissions
- The sample executes against a local SQLite simulation and does not connect to a production warehouse.
Limitations
Cost scores compare queries in the SQLite simulation and do not equal real Redshift/Athena charges.
Pinned upstream source
- Repository
- strands-agents/samples
- File path
- python/04-industry-use-cases/software-engineering/data-warehouse-optimizer/README.md
- Pinned commit
bd46f959844424a9544133e1263c8eae61e7fe9b- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: Apache-2.0
Main topic
Take a coding Agent change from context to verification