query

Analyze a SQL query and return optimization suggestions

Run EXPLAIN against the resolved connection — an estimated plan; the query is not executed — parse it, and return ranked recommendations (sequential scans, nested-loop blow-ups, MySQL filesort/temp table, and on SQL Server the optimizer's missing-index statements). Costs 1 quota unit per call. Build tier (or higher) required.

post/v1/query/optimize

Request

  • Base URL: https://data.thinair.co
  • URL: https://data.thinair.co/v1/query/optimize
  • Auth: API key in header x-api-key

Request body

connectionstring

Connection name (display) or id (uuid). When omitted, the tenant's default (first added) connection is used. Same fallback as the MCP optimize_query tool.

sqlstring required

SQL query to analyze. Read-only (SELECT / WITH / EXPLAIN). The handler runs EXPLAIN (ANALYZE false, FORMAT JSON) on Postgres, EXPLAIN on MySQL, or SET SHOWPLAN_XML ON on SQL Server — an estimated plan in every case, with no execution — and parses it for sequential/table scans, nested-loop joins, and (MySQL) temporary tables and filesorts. Missing-index CREATE statements come from the SQL Server optimizer and are therefore mssql-only. Sort spills are NOT detected on any dialect: a spill is visible only in a plan produced by actually running the query, which this tool never does.

dialect_hint'postgres' | 'mysql' | 'mssql'

Optional dialect hint. The handler derives the actual dialect from the resolved connection — this hint is informational and reserved for future cross-dialect rewrite support. On SQL Server the handler captures the ESTIMATED plan via SET SHOWPLAN_XML ON/OFF (no query execution) and returns the same recommendation shape as Postgres/MySQL (scans, missing indexes, expensive operators).

Example request

{
  "connection": "fleet",
  "sql": "SELECT * FROM drivers WHERE email = 'a@b.co'"
}

Response

Plan analysis. data.recommendations lists issues; empty + data.verdict: 'efficient' when nothing actionable was found.

dataobject required
displayobject required
summarystring
insightsobject[]
metaobject required

Changes

No recorded changes to this operation across all 1 revision of this API.