-
Notifications
You must be signed in to change notification settings - Fork 0
Concept Repeat Blocks
Turkce Dokumantasyon | English Documentation
Category: Core Concepts & Architecture
Subsystem: Data Model & Dynamic Tables (AmberDB::Base&AmberDB::Index)
Entry Type: Advanced Data Modeling Guide
Repeating Extensible Blocks (Repeat Blocks) is an AmberDB architecture feature designed to eliminate separate relational child tables (e.g. order_items, invoice_lines, product_variants) and the expensive SQL JOIN bottlenecks associated with 1-to-N relationships.
In AmberDB, a parent document (such as an Order) carries arbitrary dynamic sub-rows horizontally across its record array. Based on schema-defined repeat_start and repeat_ids configurations, the engine automatically aggregates, joins, and indexes the IDs of all child items.
Repeating Block Array Architecture (@record)
[0..14] Fixed Header Fields [15] Sub-Row 1 [16] Sub-Row 2 [17]...
┌───────────────────────────────────┐ ┌───────────────────────────┐ ┌───────────────────────────┐
│ ID, Customer, Date, Total, ... │ │ ["101", "MacBook", 1, ..] │ │ ["102", "Mouse", 2, ..] │
└───────────────────────────────────┘ └───────────────────────────┘ └───────────────────────────┘
│ │ │
│ └──────────────┬──────────────┘
v v
[12] repeat_ids (Populated by Engine) ──────────────────────> "101,102" (Indexed via match_block)
Configured within the table schema file (schema/*.table):
-
repeat_start: The 1-based block index where dynamic repeating rows begin (e.g.repeat_start => 15). -
repeat_ids: The target block index where the engine automatically joins child item IDs into a comma-separated string (e.g.repeat_ids => 12).
# dbstore/schema/order_master.table
{
name => "Orders",
repeat_ids => 12, # Target block where child product IDs are joined ("101,102,103")
repeat_start => 15, # Starting block index for dynamic repeating child rows
match_block => [ 2, 12 ], # Indexing block 12 allows instant lookup by child product ID!
fields => [
{ id => "id", name => "Order ID", type => "num" },
{ id => "customer_id", name => "Customer ID", type => "num" }, # 1
{ id => "order_date", name => "Order Date", type => "date" }, # 2
# ... (Fixed header fields 3..11) ...
{ id => "product_ids", name => "Product IDs", type => "text" }, # 12 (repeat_ids target)
{ id => "order_total", name => "Total Amount", type => "num" }, # 13
{ id => "status", name => "Status", type => "num" }, # 14
{ id => "items", name => "Order Items", type => "repeat" }, # 15 (repeat_start template)
],
}During every insert_id, modify_id, insert_list, or modify_list call, the engine (repeat_fields):
- Slices the variable array tail
@record[15..$#record]. - Extracts the primary identifier (element 0) from each child sub-row.
- Joins the non-empty IDs into a comma-separated string (
"101,102,103"). - Automatically assigns the compiled string to block 12 (
repeat_ids) before serialization and indexing.
use AmberDB;
my $adb = AmberDB->new(path => { dbase_dir => "./dbstore" });
# 1. Define order with fixed fields and repeating items starting at index 15
my @order = (
0, # [0] Auto-increment Order ID
1001, # [1] Customer ID
"2026-09-01", # [2] Date
"", "", "", "", "", "", "", "", "", # [3..11] Fixed header placeholders
"", # [12] repeat_ids (Auto-generated by engine)
2599.00, # [13] Total Amount
1, # [14] Status (Confirmed)
# Block 15+: Repeating Order Line Items ([ ItemID, Title, Qty, UnitPrice ])
[ 101, "MacBook Pro M3", 1, 2399.00 ], # [15] Item 1
[ 102, "Magic Mouse 3", 1, 200.00 ], # [16] Item 2
);
# 2. Insert order
my $order_id = $adb->insert_id("order_master", @order);
# 3. Read back and verify automated consolidation:
my @fetched = $adb->read_id("order_master", $order_id);
print "Auto-compiled Product IDs: $fetched[12]\n"; # Output: "101,102"
# 4. Instant query by child product ID (Zero JOINs!):
# Find all orders containing Product #101 via inverted match index:
my ($total, @matched_orders) = $adb->field_fetch("order_master", 12 => 101);
print "Found $total orders containing Product #101!\n";-
Zero SQL JOIN Bottlenecks: The parent document and all child lines are retrieved in a single
$O(1)$ disk read. -
Instant Inverted Queries: Querying orders containing a specific product executes via fast inverted field index (
.fld) lookups. - Atomic Consistency: Parent and child data are committed or rolled back atomically within the same record payload, preventing orphan records.
AmberDB — 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