@@ -403,6 +403,85 @@ function tests.test_update_runtime_config()
403403 print (" PASS: test_update_runtime_config" )
404404end
405405
406+ function tests .test_use_btree_config ()
407+ local path = " ./test_db_btree"
408+ cleanup_db (path )
409+
410+ local db = tidesdb .TidesDB .open (path )
411+
412+ -- Create column family with use_btree enabled
413+ local cf_config = tidesdb .default_column_family_config ()
414+ cf_config .use_btree = true
415+ db :create_column_family (" btree_cf" , cf_config )
416+
417+ local cf = db :get_column_family (" btree_cf" )
418+
419+ -- Insert some data
420+ local txn = db :begin_txn ()
421+ txn :put (cf , " key1" , " value1" )
422+ txn :put (cf , " key2" , " value2" )
423+ txn :commit ()
424+ txn :free ()
425+
426+ -- Verify use_btree in stats
427+ local stats = cf :get_stats ()
428+ assert_true (stats .use_btree ~= nil , " use_btree should exist in stats" )
429+ assert_true (stats .config .use_btree ~= nil , " use_btree should exist in config" )
430+
431+ -- Verify B+tree stats fields exist
432+ assert_true (stats .btree_total_nodes ~= nil , " btree_total_nodes should exist" )
433+ assert_true (stats .btree_max_height ~= nil , " btree_max_height should exist" )
434+ assert_true (stats .btree_avg_height ~= nil , " btree_avg_height should exist" )
435+
436+ -- Read back data to verify it works
437+ local read_txn = db :begin_txn ()
438+ local value1 = read_txn :get (cf , " key1" )
439+ local value2 = read_txn :get (cf , " key2" )
440+ assert_eq (value1 , " value1" , " get key1 with btree" )
441+ assert_eq (value2 , " value2" , " get key2 with btree" )
442+ read_txn :free ()
443+
444+ db :drop_column_family (" btree_cf" )
445+ db :close ()
446+ cleanup_db (path )
447+ print (" PASS: test_use_btree_config" )
448+ end
449+
450+ function tests .test_btree_stats_extended ()
451+ local path = " ./test_db_btree_stats"
452+ cleanup_db (path )
453+
454+ local db = tidesdb .TidesDB .open (path )
455+
456+ -- Create column family without btree (default)
457+ local cf_config = tidesdb .default_column_family_config ()
458+ cf_config .use_btree = false
459+ db :create_column_family (" block_cf" , cf_config )
460+
461+ local cf = db :get_column_family (" block_cf" )
462+
463+ -- Insert data
464+ local txn = db :begin_txn ()
465+ txn :put (cf , " key1" , " value1" )
466+ txn :commit ()
467+ txn :free ()
468+
469+ -- Verify stats
470+ local stats = cf :get_stats ()
471+ assert_eq (stats .use_btree , false , " use_btree should be false for block-based CF" )
472+ assert_eq (stats .config .use_btree , false , " config.use_btree should be false" )
473+
474+ -- B+tree stats should still exist but be zero/default for non-btree CF
475+ assert_true (stats .btree_total_nodes ~= nil , " btree_total_nodes should exist" )
476+ assert_true (stats .btree_max_height ~= nil , " btree_max_height should exist" )
477+ assert_true (stats .btree_avg_height ~= nil , " btree_avg_height should exist" )
478+
479+ db :drop_column_family (" block_cf" )
480+ db :close ()
481+ cleanup_db (path )
482+ print (" PASS: test_btree_stats_extended" )
483+ end
484+
406485-- Run all tests
407486local function run_tests ()
408487 print (" Running TidesDB Lua tests..." )
0 commit comments