Order-preserving compound keys and typed range bounds for ordered byte stores.
moon update
moon test --target wasm .
moon test --target wasm-gc .
moon test --target js .
moon run --target js examples/moonlsmpython examples/moonlsm/verify_sqlite.pymoon add WeiR-h/orderkey@0.0.8fn make_query() -> (Bytes, @orderkey.ByteRange) raise @orderkey.KeyError {
let spec = @orderkey.KeySpec::new([
BytesField(Asc), BytesField(Asc), Int64Field(Desc), Int64Field(Asc),
])
let key = spec.encode([Binary(b"t3"), Binary(b"pump"), Signed(0L), Signed(1L)])
let range = spec.field_range(
[Binary(b"t3"), Binary(b"pump")],
Inclusive(Signed(-2L)),
Exclusive(Signed(4L)),
)
(key, range)
}moon update
python examples/moonlsm/verify_reindex.py --report reindex-report.json| 字段 | 升序编码 | 降序编码 |
|---|---|---|
| Int64 | 翻转符号位,写成 8 字节大端序 | 逐字节反转升序编码的所有位 |
| Bytes | 00 转义成 00 FF,字段以 00 00 结束 | 逐字节反转升序编码的所有位 |
| 扫描路径 | 引擎返回行数 | 返回的键和值 |
|---|---|---|
| 全扫后由调用方过滤 | 9,840 | 334,560 字节 |
| 手写正确边界 | 18 | 648 字节 |
| OrderKey 生成边界 | 18 | 648 字节 |
pub suberror ContractError {
InvalidContract
ContractMismatch
InvalidCursor
CursorScopeMismatch
} derive(Debug)pub suberror KeyError {
EmptySpec
WrongArity(Int, Int)
InvalidPrefixLength(Int)
TypeMismatch(Int)
TruncatedKey(Int)
InvalidEscape(Int)
TrailingBytes(Int)
CursorOutsideRange
InvalidLayout(Int)
UnsupportedKeyFormat(Byte)
LayoutMismatch
InvalidTupleLength(Int)
} derive(Debug)pub struct IndexContract {
// private fields
}fn IndexContract::issue_cursor(self : IndexContract, snapshot_id : Bytes, range : ByteRange, last_key : Bytes) -> Bytes raisefn IndexContract::new(index_id : Bytes, generation : UInt64, fields : Array[(Bytes, Field)]) -> IndexContract raise ContractErrorfn IndexContract::resume_cursor(self : IndexContract, snapshot_id : Bytes, range : ByteRange, token : Bytes) -> ByteRange raisepub struct KeySpec {
// private fields
}fn KeySpec::tuple_range(self : KeySpec, prefix : Array[Value], first : TupleBound, last : TupleBound) -> ByteRange raise KeyErrorpub struct ReindexPlan {
// private fields
}fn ReindexPlan::new(source : IndexContract, target : IndexContract) -> ReindexPlan raise ReindexErrorInstall
Download zipOrder-preserving compound keys and typed range bounds for ordered byte stores.