Query Tuning
Send a SQL Editor query to the AI Assistant and receive rewrite or index suggestions informed by schema metadata and an estimated plan retrieved when needed.
Selecting a target
Use one read-only SELECT statement, including a WITH CTE that ends in SELECT, from the regular SQL Editor.
- When text is selected, the selected SQL takes priority.
- When there is no selection, the SQL statement containing the cursor is used.
- SQL comments are removed before the query is added to AI Chat.
The entry action does not prevalidate every selected statement. Multiple statements, write SQL, or locking SELECT statements can make estimated-plan lookup fail or produce unreliable advice, so select exactly one target statement.
Verifying database context
Query Tuning uses the Connection and database/schema selected in the active AI Chat session.
The Connection from the SQL Editor you right-clicked is not selected in AI Chat automatically. Always verify that the DB shown at the top of AI Chat matches the SQL Editor you are tuning.
Note: If another database is selected or the existing session context is locked, create a new session, select the correct Connection and schema, then start ‘AI: Tune query’ again from the SQL Editor.
How to use
Start Query Tuning from the SQL Editor context menu.
Select SQL or place the cursor
Select the SQL you want to tune. If nothing is selected, place the cursor inside the target statement.
Select AI: Tune query
Right-click the editor and select ‘AI: Tune query’. AI Chat opens with the target SQL and default tuning instructions.
Review the target and instructions
The SQL for Query Tuning block is read-only. Edit the default tuning instruction below it to match your goal.
Send and review suggestions
Select Send to start AI analysis. The AI retrieves an estimated plan and metadata when needed. Review the rewritten SQL, index suggestions, assumptions, and caveats together.

Reviewing results
Query Tuning does not modify the original SQL Editor automatically and provides evidence and candidates for review. SELECT in the answer runs automatically, while DML and DDL follow the execution policy.
- Estimated plans retrieved when needed are supported for MySQL, MariaDB, SQL Server, PostgreSQL, Oracle, and H2. SQLite does not provide an estimated plan.
- The AI can use a retrieved estimated plan plus relevant columns, keys, indexes, and relationships to suggest rewrites or indexes.
- Suggested SQL and indexes are not applied to the original SQL Editor automatically. SELECT blocks in the answer run automatically, while DML and DDL may run automatically or require confirmation according to the target Connection, database, and schema policy.
- After one send, the Query Tuning target block is removed. Start again from the SQL Editor to analyze the same SQL another time.
Caution: Rewritten SQL classified as SELECT in the answer always runs automatically. Rewritten DML and DDL follow the policy of the target Connection, database, and schema; a project owner can set those policies to ‘Confirm before execution’ for manual review.
An estimated plan cannot guarantee production data distribution or execution time. Verify semantic equivalence and compare actual plans and performance in a test environment before applying a suggestion.