AI query optimizer
Get an AI rewrite of an expensive query, with the bytes it saves and the checks it passed. On Starter, Growth, Pro and Enterprise.
The AI query optimizer takes one expensive query and suggests a cheaper version that returns the same results. The answer shows in Cognis chat. Nothing in your warehouse is changed.
Each run uses your plan's monthly AI usage: 1x on Starter, 2.5x on Growth, 5x on Pro, custom on Enterprise. The trial has none. See Plan limits.
Every plan also has a fair-use cap of 50 runs per account per day.
Start an optimization
Hover a query and click Optimize (or Optimize with Cognis AI) in one of these places:
- Dashboard → Top offenders → Top queries
- Usage → Query, on the top queries chart
- Usage → Query, in the job list of one query
Cognis opens in a new tab with the request already sent. A run takes about 30 to 40 seconds.
The click is your consent to send that query to the AI. The button tooltip says so.
What it rewrites
- Statements:
SELECT,INSERT,MERGE,UPDATE,DELETEandCREATE TABLE AS SELECT. - The query must have a run in the last 30 days that was not a cache hit. When you start from a chart, SlashPeak picks the most expensive recent run of that query.
What the answer shows
- Original query and Rewritten query, side by side.
- Bytes read before and after, and the share saved.
- Estimated monthly savings, from the number of runs in the last 30 days (on-demand pricing). On capacity pricing, the saving shows as lower slot use, not dollars.
- What changed: each edit, why, and its effect.
- Suggested, not applied: changes only a table owner can make (for example, partitioning a table).
- Check before you use it: points where results could change, such as a date range.
- Our rules: which SlashPeak rules the rewrite clears, and which still apply.
- Model confidence.
A rewrite is shown only if it reads at least 10% fewer bytes, or clears one of our rules. Otherwise the answer says "No safe rewrite found."
How bytes are checked
| Check | When | How exact |
|---|---|---|
| BigQuery dry run | Your operator key has the SQL validation group | Exact bytes, from BigQuery itself |
| Catalog estimate | No operator key with SQL validation | Sees column pruning only. A rewrite that scans a table once instead of twice shows "not estimated without a dry run" |
A dry run does not run the query and costs nothing in BigQuery.
Values are masked
Before the query goes to the AI, string values and large numbers are replaced with placeholders, and comments are removed. The AI's notes name them as ‹value 1›, ‹value 2› and so on. The rewritten SQL you see has your real values put back.
Emails, phone numbers, IP addresses and your Privacy patterns are different. They are masked inside BigQuery, so SlashPeak never has the real value. They stay as <email>, <phone>, <ip> or <redacted> in the rewrite. Put your real values back before you run it.
Free re-opens
If the same query was optimized in the last 30 days and its tables did not change, the old answer opens again. It does not use a run.
Review before you use it
The optimizer does not run the rewrite and does not compare results row by row. Read the Check before you use it list. Test the rewrite before you put it in production.
To have a fix made as a pull request in your repo, use the Cognis AI DBA instead (Growth and up).
Privacy
The optimizer runs on Google Gemini. It sends the masked query text and the table schemas it reads. It never sends table rows. See AI and your data.
Cognis chat
Ask questions about your BigQuery cost in plain English. Cognis answers from your own scan data. On Starter, Growth, Pro and Enterprise.
Cognis AI DBA docs
The AI DBA fixes findings for you: safe BigQuery changes and GitHub pull requests, each one approved, logged, checked and reversible. On Growth, Pro and Enterprise.