MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / explain_query

Method explain_query

graphlite/src/coordinator/query_coordinator.rs:783–817  ·  view source on GitHub ↗

Explain the query execution plan without executing the query This generates a detailed query plan showing how the query will be executed, including optimization steps, cost estimates, and operator tree. # Arguments `query` - The GQL query string to explain # Returns `Ok(QueryPlan)` - Detailed query execution plan `Err(String)` - Error if query cannot be planned # Example ```no_run # use graphl

(&self, query: &str)

Source from the content-addressed store, hash-verified

781 /// println!("Estimated cost: {}", plan.estimated_cost);
782 /// ```
783 pub fn explain_query(&self, query: &str) -> Result<QueryPlan, String> {
784 // Parse the query
785 let document = parse_query(query).map_err(|e| format!("Parse error: {:?}", e))?;
786
787 // Only MATCH/SELECT queries can be explained (not DDL/DML)
788 match &document.statement {
789 crate::ast::Statement::Query(_) | crate::ast::Statement::Select(_) => {
790 // Good - these can be explained
791 }
792 _ => {
793 return Err("EXPLAIN is only supported for MATCH and SELECT queries".to_string());
794 }
795 }
796
797 // Create a query planner
798 let mut planner = crate::plan::optimizer::QueryPlanner::new();
799
800 // Plan the query with tracing
801 let trace = planner
802 .plan_query_with_trace(&document)
803 .map_err(|e| format!("Planning error: {:?}", e))?;
804
805 // Use the cost and row estimates from the physical plan
806 let estimated_cost = trace.physical_plan.estimated_cost;
807 let estimated_rows = trace.physical_plan.estimated_rows;
808
809 Ok(QueryPlan {
810 logical_plan: trace.logical_plan,
811 physical_plan: trace.physical_plan,
812 planning_steps: trace.steps,
813 total_planning_time_ms: trace.total_duration.as_millis() as u64,
814 estimated_cost,
815 estimated_rows,
816 })
817 }
818}
819
820/// Query execution plan information

Callers 1

mainFunction · 0.80

Calls 2

parse_queryFunction · 0.85
plan_query_with_traceMethod · 0.80

Tested by

no test coverage detected