lu-query-tune-sql
Skill2 starsChanged 29 days agoMITView on GitHub
Use lu-query to diagnose slow or suspicious Oracle SQL - explain_plan for the real execution plan without running the statement, suggest_index for index DDL when a full scan is the problem, get_table_stats/get_column_stats/get_histogram for optimizer statistics, list_unused_indexes for index cleanup and run_sql_tuning_advisor for the advisor report.
In this repository45 other files it gives its agents.
- AGENTS.mdAGENTS.md
- api-and-interface-designSkill
- browser-testing-with-devtoolsSkill
- ci-cd-and-automationSkill
- code-review-and-qualitySkill
- code-reviewSkill
- code-simplificationSkill
- constraint-driven-developmentSkill
- debugging-and-error-recoverySkill
- deprecation-and-migrationSkill
- documentation-and-adrsSkill
- domain-modelingSkill
- doubt-driven-developmentSkill
- frontend-ui-engineeringSkill
- git-workflow-and-versioningSkill
- grill-meSkill
- grill-with-docsSkill
- implementSkill
- implement-specSkill
- improve-codebase-architectureSkill
- incremental-implementationSkill
- observability-and-instrumentationSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- prSkill
- security-and-hardeningSkill
- setup-matt-pocock-skillsSkill
- shipping-and-launchSkill
- source-driven-developmentSkill
- spec-driven-developmentSkill
- test-driven-developmentSkill
- to-specSkill
- to-ticketsSkill
- using-agent-skillsSkill
- wayfinderSkill
- writing-for-agentsSkill
- lu-query-audit-data-qualitySkill
- lu-query-audit-reportSkill
- lu-query-benchmark-sqlSkill
- lu-query-explore-schemaSkill
- lu-query-manage-schemaSkill
- lu-query-plan-data-changesSkill
- lu-query-query-dataSkill
- lu-query-triage-incidentSkill
- lu-query-use-plsqlSkill
The file
Files
Tune SQL with lu-query
When to use
- "This query is slow", "do I need that index?", "why is the optimizer choosing a full scan?"
When not to use
- The database is blocked or unreachable → lu-query-triage-incident.
- You have not measured anything yet → measure first; never "optimise" from reading SQL.
Workflow
- Get the plan without side effects on data.
explain_planon the exact SQL. It writes a row toPLAN_TABLEinside an autonomous transaction and reads it back withDBMS_XPLAN- the statement itself is not executed. - Read the plan like this:
TABLE ACCESS FULLon a filtered table is the first thing to fix;INDEX RANGE SCANis usually good; "dynamic statistics used: dynamic sampling" means the optimizer is guessing because statistics are missing or stale;Rowsestimates that are off by orders of magnitude point at bad statistics, not at a bad plan. - Confirm the statistics story.
get_table_stats(row count, blocks, last analyzed),get_column_stats(NDV, density, nulls),get_histogram(endpoints). Nulls or[]mean the table/column has never been analyzed - gather statistics as a DBA, then re-explain. - Ask for index DDL.
suggest_indexreturnsrecommendedColumnsand a readyrecommendedDdlwhen a full scan with predicates is detected. Review the DDL before running it withcreate_index(that tool commits DDL). - Escalate if needed.
run_sql_tuning_advisorgives a DBMS_SQLTUNE report with recommendations; it can be slow and it needs advisor privileges. - Clean up later.
list_unused_indexesflags indexes that look unused (LIKELY_UNUSED) - a heuristic, never drop on this signal alone.
Tool reference
| Tool | Signature | Returns |
explain_plan | sql* | DBMS_XPLAN text (plan table + predicate info + notes) |
suggest_index | sql*, targetTable? | {hasCandidates, schema, table, accessProblem, predicateColumns, recommendedColumns, recommendedDdl, reasoning} |
get_table_stats | table*, schema? | rows from the table statistics dictionary |
get_column_stats | table*, column?, schema? | rows per column |
get_histogram | table*, column*, schema? | histogram endpoints for one column |
list_unused_indexes | schema? | rows with LIKELY_UNUSED heuristic and monitoring window |
run_sql_tuning_advisor | sql* | DBMS_SQLTUNE report text |
Details: references/tools.md. Verified transcripts: references/examples.md.
Safety
explain_planwrites toPLAN_TABLE(needs the grant; the project shipsscripts/test-grants-explain.sqlfor tests).run_sql_tuning_advisorruns the advisor workload and may need the SQL Tuning Advisor pack licensed/enabled in the database; treat it as an escalation with a time limit.- Creating an index is DDL: it commits, and it costs write throughput. Propose, do not silently create.
Failure recovery
| Symptom | Cause | Action |
ORA-01031 on explain_plan | no PLAN_TABLE / advisor grants | ask for scripts/test-grants-explain.sql grants |
plan shows dynamic sampling everywhere | missing statistics | gather stats (DBA), re-run explain_plan |
get_*_stats returns nulls or [] | table/column never analyzed | expected on fresh tables; gather stats first |
| advisor report empty | statement too simple or advisor unavailable | fall back to explain_plan + suggest_index |
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.

