Skip to main content

quill_sql/execution/physical_plan/
analyze.rs

1use std::fmt::Display;
2
3use crate::catalog::{SchemaRef, EMPTY_SCHEMA_REF};
4use crate::error::QuillSQLResult;
5use crate::execution::{ExecutionContext, VolcanoExecutor};
6use crate::storage::tuple::Tuple;
7use crate::transaction::LockMode;
8use crate::utils::table_ref::TableReference;
9
10#[derive(Debug)]
11pub struct PhysicalAnalyze {
12    table: TableReference,
13}
14
15impl PhysicalAnalyze {
16    pub fn new(table: TableReference) -> Self {
17        Self { table }
18    }
19}
20
21impl VolcanoExecutor for PhysicalAnalyze {
22    fn init(&self, context: &mut ExecutionContext) -> QuillSQLResult<()> {
23        context
24            .txn_ctx_mut()
25            .lock_table(self.table.clone(), LockMode::IntentionShared)?;
26        context.catalog.analyze_table(&self.table)?;
27        Ok(())
28    }
29
30    fn next(&self, _context: &mut ExecutionContext) -> QuillSQLResult<Option<Tuple>> {
31        Ok(None)
32    }
33
34    fn output_schema(&self) -> SchemaRef {
35        EMPTY_SCHEMA_REF.clone()
36    }
37}
38
39impl Display for PhysicalAnalyze {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        write!(f, "Analyze {}", self.table)
42    }
43}