vibesql_executor/index_ddl/mod.rs
1//! CREATE INDEX, DROP INDEX, REINDEX, and ANALYZE statement execution
2//!
3//! This module provides executors for index DDL and statistics operations.
4//!
5//! # Structure
6//!
7//! ## CREATE INDEX submodules
8//! - `create_index.rs` - Main CREATE INDEX executor and dispatch logic
9//! - `validation.rs` - Pre-creation validation (column checks, privileges, etc.)
10//! - `btree_index.rs` - B-tree index creation (standard and unique)
11//! - `spatial_index.rs` - Spatial/R-tree index creation
12//! - `vector_index.rs` - IVFFlat and HNSW vector index creation
13//! - `expression_index.rs` - Expression-based functional index creation
14//!
15//! ## Other DDL operations
16//! - `drop_index.rs` - DROP INDEX executor
17//! - `reindex.rs` - REINDEX executor
18//! - `analyze.rs` - ANALYZE executor
19
20pub mod analyze;
21mod btree_index;
22pub mod create_index;
23pub mod drop_index;
24mod expression_index;
25pub mod reindex;
26mod spatial_index;
27mod validation;
28mod vector_index;
29
30pub use analyze::AnalyzeExecutor;
31pub use create_index::CreateIndexExecutor;
32pub use drop_index::DropIndexExecutor;
33pub use reindex::ReindexExecutor;
34use vibesql_ast::{CreateIndexStmt, DropIndexStmt, ReindexStmt};
35use vibesql_storage::Database;
36
37use crate::errors::ExecutorError;
38
39/// Extract the schema part of a `schema.table` qualified name.
40///
41/// CREATE INDEX builds `qualified_table_name` as `schema.table` after resolving
42/// the target table's owning schema (temp shadows main per SQLite name
43/// resolution). The schema part is what an index must be tagged with so a
44/// temp-table index lands in the temp schema. Falls back to `main` for a bare
45/// (unqualified) name. See issue #5513.
46pub(crate) fn schema_of_qualified(qualified_table_name: &str) -> &str {
47 qualified_table_name
48 .split_once('.')
49 .map(|(schema, _)| schema)
50 .unwrap_or(vibesql_catalog::DEFAULT_SCHEMA)
51}
52
53/// Unified executor for index operations (CREATE, DROP, and REINDEX INDEX)
54///
55/// This struct provides backward compatibility with the original API,
56/// delegating to specialized executors for each operation.
57pub struct IndexExecutor;
58
59impl IndexExecutor {
60 /// Execute a CREATE INDEX statement (delegates to CreateIndexExecutor)
61 pub fn execute(
62 stmt: &CreateIndexStmt,
63 database: &mut Database,
64 ) -> Result<String, ExecutorError> {
65 CreateIndexExecutor::execute(stmt, database)
66 }
67
68 /// Execute a DROP INDEX statement (delegates to DropIndexExecutor)
69 pub fn execute_drop(
70 stmt: &DropIndexStmt,
71 database: &mut Database,
72 ) -> Result<String, ExecutorError> {
73 DropIndexExecutor::execute(stmt, database)
74 }
75
76 /// Execute a REINDEX statement (delegates to ReindexExecutor)
77 pub fn execute_reindex(
78 stmt: &ReindexStmt,
79 database: &Database,
80 ) -> Result<String, ExecutorError> {
81 ReindexExecutor::execute(stmt, database)
82 }
83}