Skip to main content

dbx_core/engine/
index.rs

1//! Index API — Hash Index operations
2
3use crate::engine::Database;
4use crate::error::DbxResult;
5
6impl Database {
7    /// 인덱스를 생성합니다.
8    ///
9    /// 지정된 테이블의 컬럼에 Hash Index를 생성합니다.
10    /// O(1) 조회 성능을 제공합니다.
11    ///
12    /// # 인자
13    ///
14    /// * `table` - 테이블 이름
15    /// * `column` - 인덱스를 생성할 컬럼 이름
16    ///
17    /// # 예제
18    ///
19    /// ```rust
20    /// # use dbx_core::Database;
21    /// # fn main() -> dbx_core::DbxResult<()> {
22    /// let db = Database::open_in_memory()?;
23    /// db.create_index("users", "id")?;
24    /// # Ok(())
25    /// # }
26    /// ```
27    pub fn create_index(&self, table: &str, column: &str) -> DbxResult<()> {
28        self.index.create_index(table, column)
29    }
30
31    /// 인덱스를 삭제합니다.
32    ///
33    /// # 인자
34    ///
35    /// * `table` - 테이블 이름
36    /// * `column` - 컬럼 이름
37    pub fn drop_index(&self, table: &str, column: &str) -> DbxResult<()> {
38        self.index.drop_index(table, column)
39    }
40
41    /// 인덱스를 사용하여 행 ID를 조회합니다.
42    ///
43    /// O(1) 시간 복잡도로 조회합니다.
44    ///
45    /// # 인자
46    ///
47    /// * `table` - 테이블 이름
48    /// * `column` - 컬럼 이름
49    /// * `value` - 조회할 값
50    ///
51    /// # 반환
52    ///
53    /// 해당 값을 가진 행 ID 목록
54    pub fn index_lookup(&self, table: &str, column: &str, value: &[u8]) -> DbxResult<Vec<usize>> {
55        self.index.lookup(table, column, value)
56    }
57
58    /// 인덱스가 존재하는지 확인합니다.
59    pub fn has_index(&self, table: &str, column: &str) -> bool {
60        self.index.has_index(table, column)
61    }
62}