fraiseql_core/runtime/explain.rs
1//! Query explain plan generation.
2
3use serde::Serialize;
4
5/// Explanation of a query's execution plan, returned by the explain endpoint.
6#[derive(Debug, Clone, Serialize)]
7pub struct ExplainPlan {
8 /// The SQL query that would be executed.
9 pub sql: String,
10
11 /// Parameter bindings (name → value).
12 pub parameters: Vec<(String, serde_json::Value)>,
13
14 /// Estimated cost (from the planner heuristic).
15 pub estimated_cost: usize,
16
17 /// Views/tables that would be accessed.
18 pub views_accessed: Vec<String>,
19
20 /// Classification of the query ("regular", "mutation", "aggregate", "window", etc.).
21 pub query_type: String,
22}
23
24/// Result of `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)` run against a view
25/// with real parameter values.
26///
27/// Returned by [`Executor::explain`](crate::runtime::Executor::explain) and
28/// served by `POST /api/v1/admin/explain`.
29#[derive(Debug, Clone, Serialize)]
30pub struct ExplainResult {
31 /// The GraphQL query name that was explained (e.g., `"users"`).
32 pub query_name: String,
33
34 /// The database view the query reads from (e.g., `"v_user"`).
35 pub sql_source: String,
36
37 /// The SQL statement passed to `EXPLAIN ANALYZE` (SELECT with WHERE/LIMIT).
38 pub generated_sql: String,
39
40 /// The bound parameter values (in positional order, matching `$1`, `$2`, …).
41 pub parameters: Vec<serde_json::Value>,
42
43 /// Raw JSON output from `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)`.
44 pub explain_output: serde_json::Value,
45}