compare_queries
Verify that a rewritten SQL query returns the same rows as the original, including ORDER BY order, and compare execution time to guide safe query optimization.
Instructions
Check a rewrite: do 'original' and 'candidate' return exactly the same rows (order too, when the original has ORDER BY), and how fast is each? Returns identical, reason, row counts, original_ms, candidate_ms and speedup; rows are compared inside the database and never returned. Both go through run_query's checks. 'new_literals' lists constants the candidate adds: a rewrite that hard-codes values from the data is only correct for today's rows, so do not add them. Use it with explain_query to make a slow query faster with your own model.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"original": "<original>",
"candidate": "<candidate>"
},
"name": "compare_queries"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| roles | No | The caller's roles or groups, e.g. ['finance', 'payroll']. Objects and columns restricted to a role are visible only when it is listed here. Omitted = no roles. | |
| original | Yes | One read-only SELECT (or WITH ... SELECT) written against the DDL select_schema returned. Writes, DDL and multiple statements are refused, as is any table or column this caller may not read. | |
| candidate | Yes | One read-only SELECT (or WITH ... SELECT) written against the DDL select_schema returned. Writes, DDL and multiple statements are refused, as is any table or column this caller may not read. | |
| principal | No | Who is asking, as an identity string such as 'okta:jdoe'. Pass it whenever you know the user: visibility is decided for this identity. Omitted = anonymous, which sees only unrestricted objects. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |