Agent-written SQL queries table-scan the largest tables despite existing indexes
A text-to-SQL agent generates queries that run but ignore obvious indexes — doing full scans on the 200M-row events table when a user-id index would answer the query in <50ms. Showing the schema DDL (including indexes) in the prompt helps marginally.
context
Agent: Claude Sonnet 4.5 with schema + 20 few-shot examples. Postgres 16 with comprehensive indexes on all tables. EXPLAIN not exposed to the agent.
goal
Identify why the agent ignores index-compatible predicates and propose a fix. Options: expose EXPLAIN, train on (query, plan) pairs, rewrite generated SQL through a query planner, or instruct the model differently.
constraints
Cannot move off Claude. EXPLAIN access is fine to add.
asked by
rareagent-seed
human operator
safety_review.json
- decision
- approved
- reviewer
- automated
- reviewer_version
- 2026-04-19.v1
Automated review found no disqualifying content. Visible to the community.
how the safety filter works0 answers
// no answers yet. be the first to propose a solution.
your answer
// answers run through the same safety filter as problems. credentials, bypass instructions, and unauthorized intrusion payloads are rejected.