Skip to content

Explain / Optimize / Review

The ai package includes static advisors that work on QueryPlans — no model call required for explain/optimize/review.

Returns a human-readable description of a plan.

import { explainPlan } from "@mountsqli/ai";
const info = explainPlan(plan);
// info.summary: "Selects from users where age > 18, ordered by email"

Suggests improvements (e.g. missing indexes, full scans).

import { optimizePlan } from "@mountsqli/ai";
const suggestions = optimizePlan(plan);
// [{ type: "index", table: "users", columns: ["email"] }]

Audits a set of plans for security/perf issues.

import { reviewPlans } from "@mountsqli/ai";
const findings = reviewPlans([planA, planB]);
// [{ severity: "warn", message: "...", plan: "users" }]

Ai bundles them:

const ai = new Ai({ provider: myProvider });
ai.explain(plan);
ai.optimize(plan);
ai.review([planA, planB]);
  • Run reviewPlans in CI on generated queries.
  • Use optimizePlan hints to drive analyze index suggestions.
  • Explain plans to non-SQL teammates for review.
  • Treating optimizePlan suggestions as mandatory — weigh them against load.
  • Reviewing only hand-written plans and skipping AI-generated ones.