Updated on 2024-06-07 GMT+08:00

RCR Uheap Free Space Management

Ustore uses the free space map (FSM) file to record the free space of each data page and organizes them in the tree structure. When a user wants to perform an INSERT operation or a non-in-place update operation on a table, the user quickly searches the FSM corresponding to the table and checks whether the maximum free space recorded on the FSM is sufficient for the INSERT operation. If yes, the corresponding blocknum is returned for insertion. Otherwise, the extended page logic is executed.

The FSM structure corresponding to each table or partition is stored in an independent FSM file. The FSM file and the table data are stored in the same directory. For example, if the data file corresponding to table t1 is 32181, the corresponding FSM file is 32181_fsm. FSM is stored in the format of data blocks, which are called FSM block. The logical structure among FSM blocks is a tree with three layers of nodes. The nodes of the tree in logic are max heaps. Each time the FSM is searched from the root node to leaf nodes till an available page is returned for later service operations.

This structure may not keep real-time consistency with the actual available space of data pages and is maintained during DML execution. Ustore occasionally repairs and rebuilds FSM during autovacuum. When a user executes an INSERT DML statement, such as INSERT, NON-INPLACE UPDATE (new page), or MULTI INSERT, the FSM structure is queried to find a space where the current record can be inserted. After the DML operation is complete, the system determines whether to update the free space of the current page to the FSM based on the difference between the potential free space and the actual free space of the current page. The larger the difference, that is, the more the potential space is greater than the actual space, the higher the probability that the page is updated to the FSM. The FSM records the potential free space of data pages. When a user inserts data into a page, if the free space of the page is large, the data is directly inserted. Otherwise, if the potential space of the page is large, the page is cleaned to insert data. If the space is insufficient, search for the FSM structure again or expand the total number of pages. Updating the FSM structure involves DML statements, page cleaning, vacuum, page expansion, partition merging, and page scanning.