-
Notifications
You must be signed in to change notification settings - Fork 0
Concept 8 Byte Packed Binary Index
Turkce Dokumantasyon | English Documentation
Category: Core Concepts & Architecture
Subsystem: Indexing & Storage Engine (AmberDB::Index)
Entry Type: Architectural Concept
The 8-Byte Packed Binary Indexing Mechanism is AmberDB's core indexing format for primary ID lists (.inx), pre-sorted query matrices (.srt), and cold storage primary indexes (.jinx).
Rather than storing record IDs as variable-length text strings or serialized Perl arrays, AmberDB packs record IDs into dense, fixed-width 8-byte binary integers using Perl's pack("Q*", @ids) / pack("a8*", @ids) format. This ensures that every entry occupies exactly 8 bytes of physical storage, allowing sub-millisecond
Physical 8-Byte Packed Binary Buffer Layout (.inx / .srt)
Byte 0..7 Byte 8..15 Byte 16..23 Byte 24..31 Byte (N-1)*8..N*8
ID 1 (8-byte) ID 2 (8-byte) ID 3 (8-byte) ID 4 (8-byte) ID N (8-byte)
Pagination Offset: Start = Page * Limit * 8
Slicing: substr($buffer, $offset, $limit * 8) ==> O(1) Speed
To paginate through 1,000,000 records to fetch page 50 (records 1,000 to 1,020), traditional databases must traverse B-tree leaves or parse variable-length rows. In AmberDB:
- Slicing offset is calculated instantly:
$offset = 1000 * 8 = 8000. - Target chunk length:
$length = 20 * 8 = 160bytes. - The exact 160-byte slice is extracted via
substr($binary_buffer, 8000, 160)in$O(1)$ time. - The 20 IDs are unpacked via
unpack("Q*", $slice)without loading the remaining 999,980 records into memory.
When passing keys_only => 1 to read_all, field_fetch, or search_table, AmberDB skips loading and deserializing full record payloads from the .db master table. The unpacked binary IDs are returned directly to the caller, reducing memory footprint by over 95%.
| Metric | Serialized JSON / Array | 8-Byte Packed Binary (AmberDB) |
|---|---|---|
| Storage per 1M IDs | ~15 MB - 25 MB | 8.0 MB (Exact) |
| Pagination Slicing Cost |
|
|
| Unpacking 100 IDs | Full JSON decode overhead | < 2 microseconds |
| Cache Line Utilization | High cache pollution | Optimal L1/L2 cache locality |
# 1. Fetch page 2 (start: 20, limit: 20) with binary index optimization
my ($total_count, @page_records) = $adb->read_all("catalog_product", 20, 20);
print "Total Catalog Count: $total_count\n";
# 2. Memory-efficient scalar ID pipeline (keys_only)
my ($count, @product_ids) = $adb->read_all("catalog_product", 0, 50, keys_only => 1);
# Returns: ($count, 1001, 1002, 1003, ...) without touching .db recordsAmberDB — High-Performance Schema-Driven NoSQL Database Engine for Perl.
Copyright 2005-2026 Maruf Cetin. Released under the Artistic License 2.0.
CPAN · GitHub Repository · Issue Tracker
- Berkeley DB (DB_File) Engine
- AmberDB Table Schema
- Global Flags
- Table Schema Flags
- Directory Structure
- File Structure (Extensions)
- Repeat Blocks
- Auto-Increment ID
- ASCII ID
- Relational Records
- Record Anatomy
- JOIN-Free Architecture
- Packed Binary Index
- Strict 2PL Locking
- Undo Journal & Rollback
- Tiered Junk Indexing
- Disjunctive Faceting
- Phonetic Accent Search
- 2-Pillar Disaster Recovery
- RAM-Disk Acceleration
- In-Memory Schema Mutation
- Simple Mode
- new
- config
- set_datadir
- insert_id
- insert_list
- modify_id
- modify_list
- delete_id
- delete_list
- read_id
- read_all
- read_list
- exist_id
- exist_list
- exist_table
- table_count
- table_keys
- table_lastid
- table_attr
- table_create
- field_fetch
- field_filter
- search_table
- facet_menu
- field_fltkeys
- field_allfltkeys
- facet_rules
- slug_read
- slug_fetch
- transact_start
- transact_end
- transact_commit
- transact_rollback
- transact_recover
- flock_open
- flock_close
- cache_setup
- cache_read
- cache_write
- cache_delete
- cache_preload
- cache_ensure
- buffer_write
- buffer_read
- buffer_delete
- recs_scan
- recs_get
- recs_put
- recs_del
- locale_uc
- locale_lc
- locale_sort
- locale_to_ascii
- locale_num2text
- locale_format_currency
- locale_format_date
- array_sort
- array_punch
- array_filter
- array_sublist
- deep_copy
- log_owner
- use_counter
- use_junk
- keep_deleted
- auto_id
- buffer_write
- simple
- no_write
- no_backup
- jnktype
- keys_only
- id_type
- language
- .db · .table · .dbase
- .inx · .fld · .src
- .fac · .srt · .slg
- .unq · .del · .aut
- .cnt · .txn · .amberdb
- .csv · .cache · .tmp