Build agents
SQL performance analysis
Find slow queries, generate optimization advice, and make AskTable query faster.
SQL performance analysis tracks the duration of queries agents run on a data source, finds the slowest and most resource-intensive SQL, and generates two kinds of advice: rules AskTable can follow when generating SQL, and operations an administrator must perform in the database.
This requires a project owner or project administrator. Some data source types are not supported, and the page says so.
Entry: “More” → “Data sources” → click a data source → “Performance optimization”.
View query durations
- Trend chart: average query duration per hour; smaller is better. Hover to see duration, count, and error rate; click a point to see that day's ranking.
- Daily ranking: “Top 20 by total time” finds the main consumers, and “Top 20 by average time” finds individual slow queries. Today is shown by default (updated hourly), and you can view the past 7 days. Error counts include failures, timeouts, and cancellations.
Statistics cover only completed hours. For a new data source, data appears after the next full hour following the first query. Statistics are kept for 35 days.
Generate and apply advice
Generate an analysis
Choose a SQL statement in the ranking and click “Generate analysis”. The analysis takes some time.
Review the advice
Advice comes in two groups:
- Make AskTable query faster: for example, always use a particular filter field, or avoid a certain pattern.
- Database optimization advice (manual): for example, add an index, with copyable SQL. AskTable does not run these statements automatically; an administrator must evaluate them and act in the database.
Apply to AskTable
Click “Let AskTable use this next time”. The system filters usable rules and merges them into this data source's “Query optimization prompt”, which takes effect the next time SQL is generated.
Query optimization prompt
The “Query optimization prompt” applies only to the current data source and can be edited, enabled, or disabled manually. Each change saves a version; in “Version history” you can roll back to any version. A rollback creates a new version, and history is kept.
Common issues
| Symptom | Cause | Action |
|---|---|---|
| Not supported | The data source type does not support performance statistics | — |
| The ranking is empty | The statistics period has not ended, or there are no queries | Check again after the next full hour |
| A rule already exists | The prompt already contains the advice | No action needed |
| Queries are still slow after applying | The main bottleneck is the database | Have an administrator follow the database advice |