Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
61e0cd4
base for in-memory bestspace
hyahong Jun 5, 2026
24440ac
implement the bestspace registry and add stats for debug
hyahong Jun 9, 2026
b3ed3cc
split the allocating bit and L3
hyahong Jun 9, 2026
54fc1a7
create bestspace when creating the heap file
hyahong Jun 29, 2026
f6d6a1a
add the function that creates the bestspace
hyahong Jun 29, 2026
8f78bd0
add heap functions and candidates queue
hyahong Jul 3, 2026
165ecac
pick the new bestspaces from the candidates queue
hyahong Jul 3, 2026
4983399
stats
hyahong Jul 3, 2026
1198142
adjust the needed size according to unfill space
hyahong Jul 3, 2026
0f8c0e8
pick victim pages and replace them with selected or allocated candidates
hyahong Jul 3, 2026
cacf6c8
avoid duplicate replacement pages
hyahong Jul 4, 2026
8e6a82d
skip operation if the page is bestspace and add bestspace recovery in…
hyahong Jul 5, 2026
6ac5f20
implement updating the bestspace on disk and uses the feature in heap…
hyahong Jul 5, 2026
35fb9d1
(disk) insert the candidate page into candidates in heap header page
hyahong Jul 5, 2026
c00995e
move the prototype
hyahong Jul 5, 2026
958d1ad
make the number of shards dynamic
hyahong Jul 5, 2026
45dbcdb
uses ordered fix to avoid deadlock in bestspace path
hyahong Jul 6, 2026
160e4b9
take the bestspace pages and candidates from the heap header and shar…
hyahong Jul 6, 2026
6cced23
re-build the in-memory bestspace if there is no bestspace for class_oid
hyahong Jul 6, 2026
9c67380
make the parameter PRM_ID_HF_MAX_BESTSPACE_ENTRIES obsolete
hyahong Jul 6, 2026
8092777
add parameter and make the number of shards dynamic
hyahong Jul 6, 2026
a8fc9d4
change the usage of bestspace
hyahong Jul 6, 2026
2830dd3
change bestspace interface in heap
hyahong Jul 7, 2026
ea2e50d
make the compactdb refresh bestspace and candidates. and remove obsol…
hyahong Jul 7, 2026
83fe07f
remove legacy code and modify the show meta
hyahong Jul 7, 2026
2133630
remove the bestspace stats parts
hyahong Jul 7, 2026
ac0ed62
uese only hfid as a key
hyahong Jul 8, 2026
c0fed25
add estimates logic into shrads
hyahong Jul 8, 2026
9f2a48c
make estimates path use the atomic variable in in-memory bestspace
hyahong Jul 8, 2026
89205c9
change the heap_update_bestspace* interface
hyahong Jul 8, 2026
63ae06d
add the bestspace update logic
hyahong Jul 9, 2026
18c7349
add fallback path to refill the candidates
hyahong Jul 9, 2026
8cee1a2
fix *num_candidates to (*num_candidates)
hyahong Jul 9, 2026
ed898fe
fix comments
hyahong Jul 10, 2026
035ec4d
change lower and upper
hyahong Jul 10, 2026
ef12d70
change supplemental redo LSA log point
hyahong Jul 10, 2026
9777a21
add update path
hyahong Jul 14, 2026
f3d2e82
implement candidate queue using mutex to sort by free space in ascend…
hyahong Jul 15, 2026
9ad49ce
fix max space length calculation to use HEAP_CHAIN
hyahong Jul 15, 2026
e05124e
implement to update the heap header
hyahong Jul 15, 2026
6dbaccb
remove useless code
hyahong Jul 15, 2026
15afe33
fix overestimate of record length
hyahong Jul 16, 2026
d3fbd40
update in-memory bestspace when compactdb works as CS MODE
hyahong Jul 17, 2026
157d9b0
do not count relocation record as a new record
hyahong Jul 17, 2026
6eaf45e
do not rebuild in-memory bestspace when not existing
hyahong Jul 17, 2026
691f671
implement a pgbuf helper for calling functions without fixing pages
hyahong Jul 17, 2026
a52acf1
uses ordered callback to avoid page latch deadlock
hyahong Jul 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cubrid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ set(TRANSACTION_HEADERS
)

set(STORAGE_SOURCES
${STORAGE_DIR}/bestspace.cpp
${STORAGE_DIR}/btree.c
${STORAGE_DIR}/btree_load.c
${STORAGE_DIR}/btree_unique.cpp
Expand Down Expand Up @@ -530,6 +531,7 @@ set(STORAGE_SOURCES
${STORAGE_DIR}/tde.c
)
set(STORAGE_HEADERS
${STORAGE_DIR}/bestspace.hpp
${STORAGE_DIR}/btree_unique.hpp
${STORAGE_DIR}/double_write_buffer.hpp
${STORAGE_DIR}/ftab_set.hpp
Expand Down
8 changes: 8 additions & 0 deletions sa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ set(TRANSACTION_HEADERS
)

set(STORAGE_SOURCES
${STORAGE_DIR}/bestspace.cpp
${STORAGE_DIR}/btree.c
${STORAGE_DIR}/btree_load.c
${STORAGE_DIR}/btree_unique.cpp
Expand Down Expand Up @@ -536,6 +537,7 @@ set(STORAGE_SOURCES
${STORAGE_DIR}/tde.c
)
set(STORAGE_HEADERS
${STORAGE_DIR}/bestspace.hpp
${STORAGE_DIR}/btree_unique.hpp
${STORAGE_DIR}/ftab_set.hpp
${STORAGE_DIR}/record_descriptor.hpp
Expand Down Expand Up @@ -780,6 +782,12 @@ target_link_libraries(cubridsa
cascci
)

if(UNIX)
target_include_directories(cubridsa PUBLIC ${TBB_INCLUDES})
target_link_libraries(cubridsa PRIVATE ${TBB_LIBS})
add_dependencies(cubridsa ${TBB_TARGETS})
endif(UNIX)

add_dependencies(cubridsa
gen_csql_grammar
gen_csql_lexer
Expand Down
12 changes: 0 additions & 12 deletions src/base/perf_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,6 @@ PSTAT_METADATA pstat_Metadata[] = {
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HEAP_VACUUM_EXECUTE, "heap_vacuum_execute"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HEAP_VACUUM_LOG, "heap_vacuum_log"),

/* Execution statistics for the heap manager */
/* best space info */
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HEAP_STATS_SYNC_BESTSPACE, "heap_stats_sync_bestspace"),
PSTAT_METADATA_INIT_SINGLE_PEEK (PSTAT_HF_NUM_STATS_ENTRIES, "Num_heap_stats_bestspace_entries"),
PSTAT_METADATA_INIT_SINGLE_ACC (PSTAT_HF_NUM_STATS_MAXED, "Num_heap_stats_bestspace_maxed"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HF_BEST_SPACE_ADD, "bestspace_add"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HF_BEST_SPACE_DEL, "bestspace_del"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HF_BEST_SPACE_FIND, "bestspace_find"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HF_HEAP_FIND_PAGE_BEST_SPACE, "heap_find_page_bestspace"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_HF_HEAP_FIND_BEST_PAGE, "heap_find_best_page"),

/* B-tree detailed statistics. */
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_BT_FIX_OVF_OIDS, "bt_fix_ovf_oids"),
PSTAT_METADATA_INIT_COUNTER_TIMER (PSTAT_BT_UNIQUE_RLOCKS, "bt_unique_rlocks"),
Expand Down Expand Up @@ -4053,7 +4042,6 @@ perfmon_get_peek_stats (UINT64 * stats)
/* fixme(rem) - will be fixed in stattool patch */
#if defined (SERVER_MODE) || defined (SA_MODE)
stats[pstat_Metadata[PSTAT_PC_NUM_CACHE_ENTRIES].start_offset] = xcache_get_entry_count ();
stats[pstat_Metadata[PSTAT_HF_NUM_STATS_ENTRIES].start_offset] = heap_get_best_space_num_stats_entries ();
stats[pstat_Metadata[PSTAT_QM_NUM_HOLDABLE_CURSORS].start_offset] = session_get_number_of_holdable_cursors ();
#endif /* defined (SERVER_MODE) || defined (SA_MODE) */
}
Expand Down
11 changes: 0 additions & 11 deletions src/base/perf_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,6 @@ typedef enum
PSTAT_HEAP_VACUUM_EXECUTE,
PSTAT_HEAP_VACUUM_LOG,

/* Execution statistics for the heap manager */
/* best space info */
PSTAT_HEAP_STATS_SYNC_BESTSPACE,
PSTAT_HF_NUM_STATS_ENTRIES,
PSTAT_HF_NUM_STATS_MAXED,
PSTAT_HF_BEST_SPACE_ADD,
PSTAT_HF_BEST_SPACE_DEL,
PSTAT_HF_BEST_SPACE_FIND,
PSTAT_HF_HEAP_FIND_PAGE_BEST_SPACE,
PSTAT_HF_HEAP_FIND_BEST_PAGE,

/* B-tree ops detailed statistics. */
PSTAT_BT_FIX_OVF_OIDS,
PSTAT_BT_UNIQUE_RLOCKS,
Expand Down
18 changes: 16 additions & 2 deletions src/base/system_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ static const char sysprm_ha_conf_file_name[] = "cubrid_ha.conf";
#define PRM_NAME_LOG_POSTPONE_CACHE_SIZE "postpone_cache_size"

#define PRM_NAME_HARDWARE_AFFINITY "hardware_affinity"
#define PRM_NAME_BESTSPACE_SHARD_COUNT "bestspace_shard_count"

// #endregion

Expand Down Expand Up @@ -1197,12 +1198,13 @@ SYSPRM_PARAM prm_Def[] = {
(DUP_PRM_FUNC) NULL},
{PRM_ID_HF_MAX_BESTSPACE_ENTRIES,
PRM_NAME_HF_MAX_BESTSPACE_ENTRIES,
(PRM_FOR_SERVER | PRM_HIDDEN | PRM_USER_CHANGE),
(PRM_FOR_SERVER | PRM_HIDDEN | PRM_USER_CHANGE | PRM_OBSOLETED),
PRM_INTEGER,
PRM_CLEAR_DYNAMIC_FLAG,
{false, {.i = 1000000 /* 110 M */ }},
{false, {.i = 1000000}},
NULL_SYSPRM_PARAM_VALUE, NULL_SYSPRM_PARAM_VALUE,
NULL_SYSPRM_PARAM_VALUE,
NULL_SYSPRM_PARAM_VALUE,
(char *) NULL,
(DUP_PRM_FUNC) NULL,
(DUP_PRM_FUNC) NULL},
Expand Down Expand Up @@ -5384,6 +5386,18 @@ SYSPRM_PARAM prm_Def[] = {
(char *) NULL,
(DUP_PRM_FUNC) NULL,
(DUP_PRM_FUNC) NULL},
{PRM_ID_BESTSPACE_SHARD_COUNT,
PRM_NAME_BESTSPACE_SHARD_COUNT,
(PRM_FOR_SERVER),
PRM_INTEGER,
PRM_CLEAR_DYNAMIC_FLAG,
{false, {.i = 8}},
{false, {.i = 8}},
{false, {.i = 28}},
{false, {.i = 1}},
(char *) NULL,
(DUP_PRM_FUNC) NULL,
(DUP_PRM_FUNC) NULL}
};

SYSPRM_INDIRECT_POS prm_Def_session_idx[DIM (prm_Def)];
Expand Down
4 changes: 3 additions & 1 deletion src/base/system_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ enum param_id

PRM_ID_HARDWARE_AFFINITY,

PRM_ID_BESTSPACE_SHARD_COUNT,

/* change PRM_LAST_ID when adding new system parameters */
PRM_LAST_ID = PRM_ID_HARDWARE_AFFINITY
PRM_LAST_ID = PRM_ID_BESTSPACE_SHARD_COUNT
};
typedef enum param_id PARAM_ID;

Expand Down
2 changes: 0 additions & 2 deletions src/parser/parse_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ PT_RESERVED_NAME pt_Reserved_name_table[] = {
{"p_offset_to_free_area", RESERVED_P_OFFSET_TO_FREE_AREA, DB_TYPE_INTEGER}
,
{"p_is_saving", RESERVED_P_IS_SAVING, DB_TYPE_INTEGER}
,
{"p_update_best", RESERVED_P_UPDATE_BEST, DB_TYPE_INTEGER}

/* key info attributes */
,
Expand Down
3 changes: 1 addition & 2 deletions src/parser/parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,6 @@ typedef enum
RESERVED_P_CONT_FREE,
RESERVED_P_OFFSET_TO_FREE_AREA,
RESERVED_P_IS_SAVING,
RESERVED_P_UPDATE_BEST,

/* Reserved key info names */
RESERVED_KEY_VOLUMEID,
Expand Down Expand Up @@ -2568,7 +2567,7 @@ typedef enum
RESERVED_LAST_RECORD_INFO = RESERVED_T_MVCC_PREV_VERSION_LSA,

RESERVED_FIRST_PAGE_INFO = RESERVED_P_CLASS_OID,
RESERVED_LAST_PAGE_INFO = RESERVED_P_UPDATE_BEST,
RESERVED_LAST_PAGE_INFO = RESERVED_P_IS_SAVING,

RESERVED_FIRST_KEY_INFO = RESERVED_KEY_VOLUMEID,
RESERVED_LAST_KEY_INFO = RESERVED_KEY_OVERFLOW_OIDS,
Expand Down
19 changes: 4 additions & 15 deletions src/parser/show_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ metadata_of_slotted_page_header (void)
{"Total_free_area", "int"},
{"Contiguous_free_area", "int"},
{"Free_space_offset", "int"},
{"Need_update_best_hint", "int"},
{"Is_saving", "int"},
{"Flags", "int"}
};
Expand Down Expand Up @@ -304,21 +303,11 @@ metadata_of_heap_header (SHOW_ONLY_ALL flag)
{"Header_page_id", "int"},
{"Overflow_vfid", "varchar(64)"},
{"Next_vpid", "varchar(64)"},
{"Last_vpid", "varchar(64)"},
{"Unfill_space", "int"},
{"Estimates_num_pages", "bigint"},
{"Estimates_num_recs", "bigint"},
{"Estimates_avg_rec_len", "int"},
{"Estimates_num_high_best", "int"},
{"Estimates_num_others_high_best", "int"},
{"Estimates_head", "int"},
{"Estimates_best_list", "varchar(512)"},
{"Estimates_num_second_best", "int"},
{"Estimates_head_second_best", "int"},
{"Estimates_tail_second_best", "int"},
{"Estimates_num_substitutions", "int"},
{"Estimates_second_best_list", "varchar(256)"},
{"Estimates_last_vpid", "varchar(64)"},
{"Estimates_full_search_vpid", "varchar(64)"}
{"Num_pages", "bigint"},
{"Num_recs", "bigint"},
{"Avg_rec_len", "int"}
};

static const SHOWSTMT_COLUMN_ORDERBY orderby[] = {
Expand Down
2 changes: 0 additions & 2 deletions src/parser/xasl_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -27929,8 +27929,6 @@ pt_reserved_id_to_valuelist_index (PARSER_CONTEXT * parser, PT_RESERVED_NAME_ID
return HEAP_PAGE_INFO_OFFSET_TO_FREE_AREA;
case RESERVED_P_IS_SAVING:
return HEAP_PAGE_INFO_IS_SAVING;
case RESERVED_P_UPDATE_BEST:
return HEAP_PAGE_INFO_UPDATE_BEST;

/* Key info names */
case RESERVED_KEY_VOLUMEID:
Expand Down
10 changes: 10 additions & 0 deletions src/query/parallel/px_scan/px_scan_input_handler_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "px_scan_input_handler_heap.hpp"
#include "error_code.h"
#include "bit.h"
#include "heap_file.h"

// XXX: SHOULD BE THE LAST INCLUDE HEADER
#include "memory_wrapper.hpp"
Expand Down Expand Up @@ -158,6 +159,15 @@ namespace parallel_scan
return S_ERROR;
}

if (heap_page_is_bestspace (thread_p, m_tl_scan_cache->page_watcher.pgptr))
{
pgbuf_ordered_unfix (thread_p, &m_tl_scan_cache->page_watcher);
PGBUF_CLEAR_WATCHER (&m_tl_scan_cache->page_watcher);
/* the manual advance is only needed on the S_SUCCESS return path */
found = false;
continue;
}

*vpid = m_tl_vpid;
m_tl_pgoffset++;
m_tl_vpid.pageid++;
Expand Down
25 changes: 6 additions & 19 deletions src/query/vacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "boot_sr.h"
#include "btree.h"
#include "dbtype.h"
#include "bestspace.hpp"
#include "heap_file.h"
#include "lockfree_circular_queue.hpp"
#include "log_append.hpp"
Expand Down Expand Up @@ -1677,7 +1678,7 @@ vacuum_heap_page (THREAD_ENTRY * thread_p, VACUUM_HEAP_OBJECT * heap_objects, in
(void) pgbuf_check_page_ptype (thread_p, helper.home_page, PAGE_HEAP);
#endif /* !NDEBUG */

helper.initial_home_free_space = spage_get_free_space_without_saving (thread_p, helper.home_page, NULL);
helper.initial_home_free_space = spage_get_free_space_without_saving (thread_p, helper.home_page);

if (HFID_IS_NULL (hfid))
{
Expand Down Expand Up @@ -2416,23 +2417,8 @@ vacuum_heap_record (THREAD_ENTRY * thread_p, VACUUM_HEAP_HELPER * helper)

spage_vacuum_slot (thread_p, helper->forward_page, helper->forward_oid.slotid, true);

if (prm_get_integer_value (PRM_ID_HF_MAX_BESTSPACE_ENTRIES) > 0)
{
int freespace = spage_get_free_space_without_saving (thread_p, helper->forward_page, NULL);

if (freespace > HEAP_DROP_FREE_SPACE)
{
/*
* NOTE:
* By checking the freespace > HEAP_DROP_FREE_SPACE condition, heap_Bestspace->bestspace_mutex contention is reduced
* and the unnecessarily frequent extraction from heap_Bestspace->vpid_ht due to small free space is prevented in heap_stats_find_page_in_bestspace().
* And Passing the prev_freespace argument to 0 is a trick to get heap_stats_add_bestspace() called from heap_stats_update().
*
* This part will be refactored right away in the related issue, at which time this comment will be removed.
*/
heap_stats_update (thread_p, helper->forward_page, &helper->hfid, 0);
}
}
/* add candidate page into bestspace candidates */
heap_add_bestpage (thread_p, &helper->hfid, helper->forward_page);

VACUUM_PERF_HEAP_TRACK_EXECUTE (thread_p, helper);

Expand Down Expand Up @@ -2613,7 +2599,7 @@ vacuum_heap_page_log_and_reset (THREAD_ENTRY * thread_p, VACUUM_HEAP_HELPER * he
if (update_best_space_stat == true && helper->initial_home_free_space != -1)
{
assert (!HFID_IS_NULL (&helper->hfid));
heap_stats_update (thread_p, helper->home_page, &helper->hfid, helper->initial_home_free_space);
heap_add_bestpage (thread_p, &helper->hfid, helper->home_page, helper->initial_home_free_space);
}

VACUUM_PERF_HEAP_TRACK_EXECUTE (thread_p, helper);
Expand Down Expand Up @@ -6422,6 +6408,7 @@ vacuum_rv_notify_dropped_file (THREAD_ENTRY * thread_p, LOG_RCV * rcv)
{
(void) heap_delete_hfid_from_cache (thread_p, class_oid);
}
cubstorage::bestspaces.destroy (&rcv_data->vfid);

/* Success */
return NO_ERROR;
Expand Down
Loading
Loading