nodedb 0.4.0

Local-first, real-time, edge-to-cloud hybrid database for multi-modal workloads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
// SPDX-License-Identifier: BUSL-1.1

//! Protocol-neutral, LSN-versioned transaction read-set capture.
//!
//! Every read a transaction performs is recorded here as one or more
//! [`ReadSetEntry`]s, keyed by the same `(database_id, tenant_id, collection,
//! key)` namespace writes use so that read keys and write keys compare
//! directly. Capture is transport-agnostic: native (the canonical client),
//! pgwire, native direct-ops, and single-node multi-core fan reads all funnel
//! through [`record_read_set`], so no transport silently drops the read-set.
//!
//! A point read that HIT records [`ReadKey::Point`] carrying the row's
//! [`KeyRepr`]; an absent DOCUMENT point read records [`ReadKey::Predicate`]
//! (its placeholder surrogate would never collide with the phantom insert's
//! fresh surrogate), while an absent KV point read keeps its precise `Point`
//! key (the byte key any future write reuses). A
//! scan / search / aggregate records [`ReadKey::Predicate`] (collection scope
//! — the day-one phantom-safe floor). A multi-shard read records one entry per
//! participating shard, each stamped with that shard's own watermark LSN.
//! Absent-key / empty-result reads are recorded too: a "not found" is a
//! validatable phantom observation, not a no-op.
//!
//! No validation happens here — the entries are captured for the commit-time
//! optimistic-concurrency check to consume.

use std::net::SocketAddr;
use std::sync::Arc;

use nodedb_cluster::calvin::types::LockKeyWire;

use crate::bridge::envelope::PhysicalPlan;
use crate::control::cluster::calvin::scheduler::lock::LockKey;
use crate::control::planner::calvin::reservation::submit_reserve_read;
use crate::control::server::shared::plan_util::{extract_collection, plan_engine, read_key_of};
use crate::control::state::SharedState;
use crate::types::{DatabaseId, KeyRepr, Lsn, TenantId, VShardId};

use super::store::SessionStore;

/// Which peer engine served a read. Mirrors the top-level [`PhysicalPlan`]
/// variants one-to-one so the classifier is total and a new engine forces a
/// decision at compile time.
///
/// Defined in `nodedb-types` because it also travels on the replicated Calvin
/// `TxClass` versioned read-set; re-exported here so read-capture call sites
/// keep referring to it by this path.
pub use nodedb_types::calvin::EngineTag;

/// The identity a read observed within a collection.
///
/// `Point` carries the exact row identity for a keyed lookup (per-key OCC
/// validation later). `Predicate` is the coarse, collection-scoped observation
/// for scans / searches / aggregates and for keyed ops whose observation spans
/// more than one row (batch gets, secondary-index equality) — safe against
/// phantoms, never under-approximating. A future refinement may narrow
/// `Predicate` to an index-range signature without a type change.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReadKey {
    /// A single-row keyed observation.
    Point { repr: KeyRepr },
    /// A collection-scoped predicate observation.
    Predicate,
    /// A secondary-index equality observation on one indexed field, carrying
    /// the canonical stringified index value.
    IndexEq { field: String, value: String },
    /// A secondary-index range observation on one indexed field. `lo`/`hi` are
    /// optional so a one-sided native range is representable; both `None` is
    /// never emitted.
    IndexRange {
        field: String,
        lo: Option<String>,
        hi: Option<String>,
    },
}

/// One LSN-versioned, predicate-aware read-set entry. Scoped by
/// `(database_id, tenant_id)` exactly like the write path so two tenants (or
/// databases) never alias.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReadSetEntry {
    pub engine: EngineTag,
    pub database_id: DatabaseId,
    pub tenant_id: TenantId,
    pub collection: String,
    pub key: ReadKey,
    pub read_lsn: Lsn,
    /// Per-collection read-version LSN (the read collection's `coll_write_lsn`
    /// at read time, a WAL LSN) — the SOUND comparand for cross-shard OCC
    /// validation, which compares it against the same collection's recorded
    /// write versions in that one domain. `read_lsn` above stays the core-global
    /// watermark used by single-shard SI (`si_conflict_abort`).
    pub read_version_lsn: Lsn,
}

/// The observed read passed to [`record_read_set`]: the executed plan, the
/// responding shards' write-LSN watermarks, the read-version floor, and whether
/// a point read hit.
pub struct ReadCapture<'a> {
    pub plan: &'a PhysicalPlan,
    pub watermarks: &'a [(VShardId, Lsn)],
    pub read_version_lsn: Lsn,
    pub found: bool,
}

/// Record a completed read into the session's transaction read-set.
///
/// Transport-agnostic: every read post-dispatch seam calls this with the plan
/// that ran and the per-shard watermark(s) it observed. Records one
/// [`ReadSetEntry`] per `(vshard, watermark)` pair — a predicate read fanned
/// over N shards yields N entries, each carrying that shard's own watermark
/// LSN. A point read observes a single shard and yields one entry.
///
/// Guarded on the connection being inside a transaction block (the session
/// write path drops the entries otherwise), so autocommit reads never touch
/// the read-set. Absent-key / empty-result reads MUST reach this with a
/// non-empty `watermarks` slice — a "not found" is a validatable observation.
///
/// `read_version_lsn` is the read collection's per-collection write floor at
/// read time (a WAL LSN) — one scalar, since a read op
/// resolves to a single collection (joins collapse to one via
/// `extract_collection`). It stamps every entry produced here and is the SOUND
/// comparand cross-shard OCC validation consumes; the per-shard `watermarks`
/// still source the core-global `read_lsn` used by single-shard SI.
///
/// `found` reports whether a point read observed a present row (`true` on a
/// hit, `false` on a miss). It only affects document point reads — an absent
/// document read degrades to a collection-scoped predicate; see [`read_key_of`].
pub async fn record_read_set(
    state: &SharedState,
    sessions: &SessionStore,
    addr: &SocketAddr,
    tenant_id: TenantId,
    capture: ReadCapture<'_>,
) {
    let ReadCapture {
        plan,
        watermarks,
        read_version_lsn,
        found,
    } = capture;
    if watermarks.is_empty() {
        return;
    }

    let engine = plan_engine(plan);
    let key = read_key_of(plan, found);
    let collection = extract_collection(plan)
        .map(String::from)
        .unwrap_or_default();
    // Scope exactly like writes: the caller passes the authenticated
    // `tenant_id` (from the dispatched task / identity), and the database is the
    // session's current database.
    let database_id = sessions
        .get_current_database(addr)
        .unwrap_or(DatabaseId::DEFAULT);

    // Read-your-writes floor: raise the captured read-version to the session's
    // OWN highest committed write-version for this collection. Without it, a
    // read that observed a stale collection floor (0) before the session's own
    // prior committed write was reflected on the serving core would, at
    // cross-shard OCC validation, see that write's `coll_write_lsn` exceed the
    // read-version and false-abort with a serialization failure on the session's
    // OWN write. The floor is only ever raised by this session's own committed
    // writes to this exact `(database, tenant, collection)`, so a concurrent
    // OTHER-session write (higher `coll_write_lsn`) still exceeds the floor and
    // still aborts — this removes only the self-abort. `read_lsn` (the per-shard
    // watermark used by single-shard SI) is deliberately left untouched.
    let own_write_version = sessions.own_write_version(addr, database_id, tenant_id, &collection);
    let effective_read_version = read_version_lsn.max(own_write_version);

    let entries: Vec<ReadSetEntry> = watermarks
        .iter()
        .map(|(_vshard, read_lsn)| ReadSetEntry {
            engine,
            database_id,
            tenant_id,
            collection: collection.clone(),
            key: key.clone(),
            read_lsn: *read_lsn,
            read_version_lsn: effective_read_version,
        })
        .collect();

    sessions.record_read_entries(addr, entries);

    // RESERVE-AT-READ: when an interactive transaction reads a HOT point key,
    // take a sequenced SHARED reservation on it and remember the granted owner on
    // the session so the eventual commit can carry it as `lock_owner`. The
    // reservation is a hint — `is_hot` varies per node, and a failed/absent
    // reservation simply means the read proceeds under plain OCC. It never
    // changes the read result and never fails the read.

    // Autocommit reads never reserve: there is no transaction to carry the owner.
    if !sessions.is_in_transaction_block(addr) {
        return;
    }

    // Only single-row point reads are lockable; scans / index / absent-document
    // observations have no single lock key to reserve.
    let Some(lock_key) = lock_key_of_read(&key, &collection) else {
        return;
    };

    // Hotness check — scope the table guard so it drops BEFORE any await.
    let now = std::time::Instant::now();
    let hot = {
        let table = state
            .hot_key_table
            .lock()
            .unwrap_or_else(|p| p.into_inner());
        table.is_hot(&lock_key, now)
    };
    if !hot {
        return;
    }

    // Route the shared reservation to the SAME vshard the commit batch will use
    // for this key (write/commit routing derives the shard identically), so the
    // self-upgrade at commit finds the shared lock on the right scheduler.
    let vshard = VShardId::from_collection_in_database(database_id, &collection).as_u32();
    // Reuse the transaction's single reservation owner (None on the first hot-key
    // read; the assignment mints it, and `record_reservation` adopts it). Guard
    // dropped inside the accessor — nothing is held across the await below.
    let owner = sessions.current_reservation_owner(addr);
    let wire_key = lock_key_to_wire(&lock_key);
    match submit_reserve_read(state, wire_key, vshard, owner).await {
        Ok(r) => sessions.record_reservation(addr, vshard, r),
        Err(e) => {
            tracing::debug!(error = %e, "hot-key read reservation failed; proceeding under OCC");
        }
    }
}

/// Map a completed point read (`ReadKey` + collection) to the deterministic CP
/// [`LockKey`] it observed, when the read was a single-row point read
/// (`Surrogate` or `KvKey`). Every other shape (predicate / index-eq /
/// index-range scans, absent document) has no single lock key to reserve.
///
/// `pub(super)` so [`super::hot_key::record_read_set_aborts`] can reuse the
/// same construction instead of duplicating the `KeyRepr` match against a
/// [`ReadSetEntry`]'s `(key, collection)` pair.
pub(super) fn lock_key_of_read(key: &ReadKey, collection: &str) -> Option<LockKey> {
    match key {
        ReadKey::Point {
            repr: KeyRepr::Surrogate(s),
        } => Some(LockKey::Surrogate {
            collection: Arc::from(collection),
            surrogate: *s,
        }),
        ReadKey::Point {
            repr: KeyRepr::KvKey(k),
        } => Some(LockKey::Kv {
            collection: Arc::from(collection),
            key: Arc::from(&**k),
        }),
        _ => None,
    }
}

/// Convert a CP [`LockKey`] into its [`LockKeyWire`] transport twin — the
/// inverse of the scheduler driver's `decode_lock_key`.
fn lock_key_to_wire(key: &LockKey) -> LockKeyWire {
    match key {
        LockKey::Surrogate {
            collection,
            surrogate,
        } => LockKeyWire::Surrogate {
            collection: collection.to_string(),
            surrogate: *surrogate,
        },
        LockKey::Kv { collection, key } => LockKeyWire::Kv {
            collection: collection.to_string(),
            key: key.to_vec(),
        },
        LockKey::Edge {
            collection,
            src,
            dst,
        } => LockKeyWire::Edge {
            collection: collection.to_string(),
            src: *src,
            dst: *dst,
        },
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use nodedb_physical::physical_plan::{DocumentOp, KvOp};

    fn addr() -> SocketAddr {
        "127.0.0.1:5599".parse().expect("test addr")
    }

    fn kv_get(collection: &str, key: &[u8]) -> PhysicalPlan {
        PhysicalPlan::Kv(KvOp::Get {
            collection: collection.to_string(),
            key: key.to_vec(),
            rls_filters: Vec::new(),
            surrogate_ceiling: None,
        })
    }

    fn kv_batch_get(collection: &str) -> PhysicalPlan {
        PhysicalPlan::Kv(KvOp::BatchGet {
            collection: collection.to_string(),
            keys: vec![b"a".to_vec(), b"b".to_vec()],
        })
    }

    fn begun_session() -> (SessionStore, SocketAddr) {
        let sessions = SessionStore::new();
        let a = addr();
        sessions.ensure_session(a);
        sessions.begin(&a, Lsn::new(5), 0).expect("begin");
        (sessions, a)
    }

    /// Build a minimal `SharedState` for the read-capture seam. The hot-key
    /// table starts empty, so `is_hot` is always false here and the
    /// reserve-at-read path is a no-op — these tests exercise read-set capture,
    /// not reservation. The returned `TempDir` must outlive the state (it backs
    /// the test WAL).
    fn test_state() -> (std::sync::Arc<SharedState>, tempfile::TempDir) {
        use crate::bridge::dispatch::Dispatcher;
        use crate::wal::WalManager;

        let dir = tempfile::tempdir().expect("tempdir");
        let wal = std::sync::Arc::new(
            WalManager::open_for_testing(&dir.path().join("test.wal")).expect("wal"),
        );
        let (dispatcher, _data_sides) = Dispatcher::new(1, 64);
        let state = SharedState::new(dispatcher, wal).expect("shared state");
        (state, dir)
    }

    #[tokio::test]
    async fn point_read_records_point_key() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_get("c", b"k1"),
                watermarks: &[(VShardId::new(0), Lsn::new(7))],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 1);
        assert_eq!(rs[0].engine, EngineTag::Kv);
        assert_eq!(rs[0].collection, "c");
        assert_eq!(rs[0].read_lsn, Lsn::new(7));
        assert_eq!(
            rs[0].key,
            ReadKey::Point {
                repr: KeyRepr::KvKey(Box::from(b"k1".as_slice())),
            }
        );
    }

    #[tokio::test]
    async fn predicate_read_records_predicate_key() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        // A batch get spans multiple keys — recorded as a collection-scoped
        // predicate (never under-approximated to a single key).
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_batch_get("c"),
                watermarks: &[(VShardId::new(0), Lsn::new(9))],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 1);
        assert_eq!(rs[0].key, ReadKey::Predicate);
    }

    #[tokio::test]
    async fn multi_shard_read_records_one_entry_per_watermark() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        // A predicate fanned over three cores records one entry per shard, each
        // stamped with that shard's own watermark — NOT a single collapsed max.
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_batch_get("c"),
                watermarks: &[
                    (VShardId::new(0), Lsn::new(3)),
                    (VShardId::new(1), Lsn::new(11)),
                    (VShardId::new(2), Lsn::new(7)),
                ],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 3);
        let mut lsns: Vec<u64> = rs.iter().map(|e| e.read_lsn.as_u64()).collect();
        lsns.sort_unstable();
        assert_eq!(lsns, vec![3, 7, 11]);
    }

    #[tokio::test]
    async fn absent_key_point_read_is_recorded() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        // A "not found" is a validatable phantom observation: the KV point entry
        // is recorded (as `found = false`) at the current watermark. KV keeps the
        // precise byte key — the identity any future insert of that key reuses.
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_get("c", b"missing"),
                watermarks: &[(VShardId::new(0), Lsn::new(5))],
                read_version_lsn: Lsn::ZERO,
                found: false,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 1);
        assert_eq!(
            rs[0].key,
            ReadKey::Point {
                repr: KeyRepr::KvKey(Box::from(b"missing".as_slice())),
            }
        );
    }

    fn doc_point_get(collection: &str, surrogate: u32) -> PhysicalPlan {
        PhysicalPlan::Document(DocumentOp::PointGet {
            collection: collection.to_string(),
            document_id: "d".to_string(),
            surrogate: nodedb_types::Surrogate::new(surrogate),
            pk_bytes: Vec::new(),
            rls_filters: Vec::new(),
            system_time: Default::default(),
            valid_at_ms: None,
        })
    }

    #[tokio::test]
    async fn document_point_read_hit_records_precise_surrogate() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        // A hit keeps the precise cross-engine surrogate so the common case is
        // validated per-key (no over-abort).
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &doc_point_get("docs", 42),
                watermarks: &[(VShardId::new(0), Lsn::new(7))],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 1);
        assert_eq!(
            rs[0].key,
            ReadKey::Point {
                repr: KeyRepr::Surrogate(42),
            }
        );
    }

    #[tokio::test]
    async fn absent_document_point_read_records_predicate() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        // A miss degrades to the collection-scoped predicate: the placeholder
        // surrogate would never collide with a phantom insert's fresh surrogate,
        // so the collection floor is the only safe read identity.
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &doc_point_get("docs", 999),
                watermarks: &[(VShardId::new(0), Lsn::new(5))],
                read_version_lsn: Lsn::ZERO,
                found: false,
            },
        )
        .await;
        let rs = sessions.take_read_set(&a);
        assert_eq!(rs.len(), 1);
        assert_eq!(rs[0].key, ReadKey::Predicate);
    }

    #[tokio::test]
    async fn autocommit_reads_are_not_recorded() {
        let (state, _dir) = test_state();
        let sessions = SessionStore::new();
        let a = addr();
        sessions.ensure_session(a);
        // No BEGIN: outside a transaction block the read-set stays empty.
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_get("c", b"k1"),
                watermarks: &[(VShardId::new(0), Lsn::new(7))],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        assert!(sessions.take_read_set(&a).is_empty());
    }

    #[tokio::test]
    async fn empty_watermarks_records_nothing() {
        let (state, _dir) = test_state();
        let (sessions, a) = begun_session();
        record_read_set(
            &state,
            &sessions,
            &a,
            TenantId::new(1),
            ReadCapture {
                plan: &kv_get("c", b"k1"),
                watermarks: &[],
                read_version_lsn: Lsn::ZERO,
                found: true,
            },
        )
        .await;
        assert!(sessions.take_read_set(&a).is_empty());
    }

    #[test]
    fn point_get_document_uses_surrogate_identity() {
        let plan = PhysicalPlan::Document(DocumentOp::PointGet {
            collection: "docs".to_string(),
            document_id: "d1".to_string(),
            surrogate: nodedb_types::Surrogate::new(42),
            pk_bytes: Vec::new(),
            rls_filters: Vec::new(),
            system_time: Default::default(),
            valid_at_ms: None,
        });
        assert_eq!(
            read_key_of(&plan, true),
            ReadKey::Point {
                repr: KeyRepr::Surrogate(42),
            }
        );
        assert_eq!(plan_engine(&plan), EngineTag::Document);
    }

    fn indexed_fetch(collection: &str, path: &str, value: &str) -> PhysicalPlan {
        PhysicalPlan::Document(DocumentOp::IndexedFetch {
            collection: collection.to_string(),
            path: path.to_string(),
            value: value.to_string(),
            filters: Vec::new(),
            projection: Vec::new(),
            limit: 0,
            offset: 0,
        })
    }

    fn range_scan(
        collection: &str,
        field: &str,
        lower: Option<&[u8]>,
        upper: Option<&[u8]>,
    ) -> PhysicalPlan {
        PhysicalPlan::Document(DocumentOp::RangeScan {
            collection: collection.to_string(),
            field: field.to_string(),
            lower: lower.map(|b| b.to_vec()),
            upper: upper.map(|b| b.to_vec()),
            limit: 0,
        })
    }

    #[test]
    fn indexed_fetch_always_records_index_eq() {
        // A secondary-index equality read always captures the indexed field +
        // canonical value.
        let plan = indexed_fetch("users", "$.email", "a@b.c");
        assert_eq!(
            read_key_of(&plan, true),
            ReadKey::IndexEq {
                field: "$.email".to_string(),
                value: "a@b.c".to_string(),
            }
        );
    }

    #[test]
    fn range_scan_always_records_index_range() {
        let plan = range_scan("users", "$.age", Some(b"18"), Some(b"65"));
        assert_eq!(
            read_key_of(&plan, true),
            ReadKey::IndexRange {
                field: "$.age".to_string(),
                lo: Some("18".to_string()),
                hi: Some("65".to_string()),
            }
        );
    }
}