From 05d8cca75c7a05e480673aa672a310f1764d66de Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 29 Sep 2025 18:44:43 +0300 Subject: [PATCH] core: Disallow CREATE INDEX when MVCC is enabled MVCC does currently not support indexes. Therefore, - Fail if a database with indexes is opened with MVCC - Disallow `CREATE INDEX` when MVCC is enabled Fixes: #3108 --- core/lib.rs | 16 ++++++++++++++++ core/translate/index.rs | 3 +++ 2 files changed, 19 insertions(+) diff --git a/core/lib.rs b/core/lib.rs index 79d828250..806d44c76 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -476,6 +476,14 @@ impl Database { // a warning to the user to load the module eprintln!("Warning: {e}"); } + + if db.mvcc_enabled() && !schema.indexes.is_empty() { + return Err(LimboError::ParseError( + "Database contains indexes which are not supported when MVCC is enabled." + .to_string(), + )); + } + Ok(()) })?; } @@ -827,6 +835,10 @@ impl Database { pub fn experimental_strict_enabled(&self) -> bool { self.opts.enable_strict } + + pub fn mvcc_enabled(&self) -> bool { + self.opts.enable_mvcc + } } #[derive(Debug, Clone, Eq, PartialEq)] @@ -1903,6 +1915,10 @@ impl Connection { self.db.experimental_strict_enabled() } + pub fn mvcc_enabled(&self) -> bool { + self.db.mvcc_enabled() + } + /// Query the current value(s) of `pragma_name` associated to /// `pragma_value`. /// diff --git a/core/translate/index.rs b/core/translate/index.rs index 44930fb08..13538e7b4 100644 --- a/core/translate/index.rs +++ b/core/translate/index.rs @@ -39,6 +39,9 @@ pub fn translate_create_index( if tbl_name.eq_ignore_ascii_case("sqlite_sequence") { crate::bail_parse_error!("table sqlite_sequence may not be indexed"); } + if connection.mvcc_enabled() { + crate::bail_parse_error!("CREATE INDEX is currently not supported when MVCC is enabled."); + } if !resolver.schema.indexes_enabled() { crate::bail_parse_error!( "CREATE INDEX is disabled by default. Run with `--experimental-indexes` to enable this feature."