Register a new sorted index with backfill from existing KV data. Scans the hash table for all entries, extracts sort key columns, and populates the order-statistic tree. Returns backfill count.
(
&mut self,
tenant_id: u64,
collection: &str,
def: SortedIndexDef,
)
| 17 | /// Scans the hash table for all entries, extracts sort key columns, |
| 18 | /// and populates the order-statistic tree. Returns backfill count. |
| 19 | pub fn register_sorted_index( |
| 20 | &mut self, |
| 21 | tenant_id: u64, |
| 22 | collection: &str, |
| 23 | def: SortedIndexDef, |
| 24 | ) -> u32 { |
| 25 | let tkey = table_key(tenant_id, collection); |
| 26 | let now_ms = super::current_ms(); |
| 27 | |
| 28 | // Collect existing entries from the hash table for backfill. |
| 29 | let entries: Vec<(Vec<u8>, Vec<u8>)> = self |
| 30 | .tables |
| 31 | .get(&tkey) |
| 32 | .map(|t| { |
| 33 | let (entries, _) = t.scan(0, usize::MAX, now_ms, None); |
| 34 | entries |
| 35 | .into_iter() |
| 36 | .map(|(k, v)| (k.to_vec(), v.to_vec())) |
| 37 | .collect() |
| 38 | }) |
| 39 | .unwrap_or_default(); |
| 40 | |
| 41 | self.sorted_indexes |
| 42 | .register(tenant_id, def, entries.into_iter()) |
| 43 | } |
| 44 | |
| 45 | /// Drop a sorted index. Returns `true` if it existed. |
| 46 | pub fn drop_sorted_index(&mut self, tenant_id: u64, index_name: &str) -> bool { |
no test coverage detected