From 0a4e094ef6597837bec6bf3f246ea65367364762 Mon Sep 17 00:00:00 2001 From: Bennett Clement Date: Sat, 20 Jul 2024 00:35:15 +0800 Subject: [PATCH] Update COMPAT table and remove unused deps --- COMPAT.md | 2 +- Cargo.lock | 49 ------------------------------------------------- core/Cargo.toml | 1 - core/btree.rs | 6 +++--- core/pseudo.rs | 6 +++--- core/sorter.rs | 44 +++++++++++++++++++++++++------------------- core/types.rs | 2 +- core/vdbe.rs | 4 ++-- 8 files changed, 35 insertions(+), 79 deletions(-) diff --git a/COMPAT.md b/COMPAT.md index 12c34115c..1cde4971d 100644 --- a/COMPAT.md +++ b/COMPAT.md @@ -44,7 +44,7 @@ This document describes the SQLite compatibility status of Limbo: | SELECT ... WHERE | Partial | | | SELECT ... WHERE ... LIKE | Yes | | | SELECT ... LIMIT | Yes | | -| SELECT ... ORDER BY | No | | +| SELECT ... ORDER BY | Partial | | | SELECT ... GROUP BY | No | | | SELECT ... JOIN | Partial | | | SELECT ... CROSS JOIN | Partial | | diff --git a/Cargo.lock b/Cargo.lock index 9be5c8555..f3737cf57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,26 +357,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "const-random" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom", - "once_cell", - "tiny-keccak", -] - [[package]] name = "cpp_demangle" version = "0.4.3" @@ -505,15 +485,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "dlv-list" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" -dependencies = [ - "const-random", -] - [[package]] name = "either" version = "1.13.0" @@ -1005,7 +976,6 @@ dependencies = [ "log", "mimalloc", "nix 0.29.0", - "ordered-multimap", "polling", "pprof", "regex", @@ -1171,16 +1141,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "ordered-multimap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" -dependencies = [ - "dlv-list", - "hashbrown 0.14.5", -] - [[package]] name = "os_str_bytes" version = "6.6.1" @@ -1809,15 +1769,6 @@ dependencies = [ "syn 2.0.69", ] -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - [[package]] name = "tinytemplate" version = "1.2.1" diff --git a/core/Cargo.toml b/core/Cargo.toml index 4a4dbe5b5..b94931e30 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -34,7 +34,6 @@ fallible-iterator = "0.3.0" libc = "0.2.155" log = "0.4.20" nix = { version = "0.29.0", features = ["fs"] } -ordered-multimap = "0.7.1" sieve-cache = "0.1.4" sqlite3-parser = "0.11.0" thiserror = "1.0.61" diff --git a/core/btree.rs b/core/btree.rs index e56a890cd..0ac1e5331 100644 --- a/core/btree.rs +++ b/core/btree.rs @@ -4,7 +4,7 @@ use crate::types::{Cursor, CursorResult, OwnedRecord}; use anyhow::Result; -use std::cell::RefCell; +use std::cell::{Ref, RefCell}; use std::rc::Rc; pub struct MemPage { @@ -156,8 +156,8 @@ impl Cursor for BTreeCursor { Ok(*self.rowid.borrow()) } - fn record(&self) -> Result> { - Ok(self.record.borrow().to_owned()) + fn record(&self) -> Result>> { + Ok(self.record.borrow()) } fn insert(&mut self, _record: &OwnedRecord) -> Result<()> { diff --git a/core/pseudo.rs b/core/pseudo.rs index ddcc5f483..dd8668d2e 100644 --- a/core/pseudo.rs +++ b/core/pseudo.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use std::cell::RefCell; +use std::cell::{Ref, RefCell}; use crate::types::{Cursor, CursorResult, OwnedRecord, OwnedValue}; @@ -46,8 +46,8 @@ impl Cursor for PseudoCursor { Ok(x) } - fn record(&self) -> Result> { - Ok(self.current.borrow().to_owned()) + fn record(&self) -> Result>> { + Ok(self.current.borrow()) } fn insert(&mut self, record: &OwnedRecord) -> Result<()> { diff --git a/core/sorter.rs b/core/sorter.rs index 867a98f52..2e0bf74d1 100644 --- a/core/sorter.rs +++ b/core/sorter.rs @@ -1,13 +1,13 @@ use crate::types::{Cursor, CursorResult, OwnedRecord}; use anyhow::Result; use std::{ - cell::RefCell, + cell::{Ref, RefCell}, collections::{BTreeMap, VecDeque}, }; pub struct Sorter { records: BTreeMap>, - current: RefCell>>, + current: RefCell>, order: Vec, } @@ -35,25 +35,32 @@ impl Cursor for Sorter { } fn rewind(&mut self) -> Result> { - let empty = { - let current = self.current.borrow(); - current.as_ref().map(|r| r.is_empty()).unwrap_or(true) - }; - if empty { - let mut c = self.current.borrow_mut(); - *c = self.records.pop_first().map(|(_, record)| record); + let mut c = self.current.borrow_mut(); + for (_, record) in self.records.iter_mut() { + let record = record.pop_front(); + if record.is_some() { + *c = record; + break; + } } + Ok(CursorResult::Ok(())) } fn next(&mut self) -> Result> { - let empty = { - let current = self.current.borrow(); - current.as_ref().map(|r| r.is_empty()).unwrap_or(true) - }; - if empty { - let mut c = self.current.borrow_mut(); - *c = self.records.pop_first().map(|(_, record)| record); + let mut c = self.current.borrow_mut(); + let mut matched = false; + for (_, record) in self.records.iter_mut() { + let record = record.pop_front(); + if record.is_some() { + *c = record; + matched = true; + break; + } + } + self.records.retain(|_, v| !v.is_empty()); + if !matched { + *c = None; } Ok(CursorResult::Ok(())) } @@ -66,9 +73,8 @@ impl Cursor for Sorter { todo!(); } - fn record(&self) -> Result> { - let mut current = self.current.borrow_mut(); - Ok(current.as_mut().map(|r| r.pop_front().unwrap())) + fn record(&self) -> Result>> { + Ok(self.current.borrow()) } fn insert(&mut self, record: &OwnedRecord) -> Result<()> { diff --git a/core/types.rs b/core/types.rs index 790c47c9c..137f8e8fd 100644 --- a/core/types.rs +++ b/core/types.rs @@ -297,7 +297,7 @@ pub trait Cursor { fn next(&mut self) -> Result>; fn wait_for_completion(&mut self) -> Result<()>; fn rowid(&self) -> Result>; - fn record(&self) -> Result>; + fn record(&self) -> Result>>; fn insert(&mut self, record: &OwnedRecord) -> Result<()>; fn set_null_flag(&mut self, flag: bool); fn get_null_flag(&self) -> bool; diff --git a/core/vdbe.rs b/core/vdbe.rs index e28e7b93c..adbe7dc72 100644 --- a/core/vdbe.rs +++ b/core/vdbe.rs @@ -892,7 +892,7 @@ impl Program { dest, } => { let cursor = cursors.get_mut(cursor_id).unwrap(); - if let Some(ref record) = cursor.record()? { + if let Some(ref record) = *cursor.record()? { let null_flag = cursor.get_null_flag(); state.registers[*dest] = if null_flag { OwnedValue::Null @@ -1228,7 +1228,7 @@ impl Program { pseudo_cursor: sorter_cursor, } => { let cursor = cursors.get_mut(cursor_id).unwrap(); - let record = match cursor.record()? { + let record = match *cursor.record()? { Some(ref record) => record.clone(), None => { todo!();