fnck_sql/execution/dql/
explain.rs

1use crate::execution::{Executor, ReadExecutor};
2use crate::planner::LogicalPlan;
3use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache};
4use crate::types::tuple::Tuple;
5use crate::types::value::{DataValue, Utf8Type};
6use sqlparser::ast::CharLengthUnits;
7
8pub struct Explain {
9    plan: LogicalPlan,
10}
11
12impl From<LogicalPlan> for Explain {
13    fn from(plan: LogicalPlan) -> Self {
14        Explain { plan }
15    }
16}
17
18impl<'a, T: Transaction + 'a> ReadExecutor<'a, T> for Explain {
19    fn execute(
20        self,
21        _: (&'a TableCache, &'a ViewCache, &'a StatisticsMetaCache),
22        _: *mut T,
23    ) -> Executor<'a> {
24        Box::new(
25            #[coroutine]
26            move || {
27                let values = vec![DataValue::Utf8 {
28                    value: self.plan.explain(0),
29                    ty: Utf8Type::Variable(None),
30                    unit: CharLengthUnits::Characters,
31                }];
32
33                yield Ok(Tuple::new(None, values));
34            },
35        )
36    }
37}