KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Maintaining Tables with Many Deletes and Creates
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: September 12, 2022

Some databases have tables that can experience many creation and deletion of records. A problematic issue that can occur with these tables is fragmentation of the data. When a record is deleted, it's space is no longer occurpied allowing for new data to be written to it. Unless a new record is the exact same size as the space, it will be smaller than the space and leave some fragmentation. As the fragmentation of the data builds up, this can cause some actions, such as a simple query, on the table to decrease in performance.

As such, a recomended maintanence task, is to regularly check if tables with frequent creates and deletes for fragmentation, and perform a compact if needed. This will improve the performance of interacting with these tables.

The fragmentation of the tables can be found in many ways. One way is to use the Get table fragmentation command. The command will return the fragmentation percentage of the table as a real value. It is suggested that if the table's fragmentation is above 20% a compact should be performed.

An alternative method to check for fragmentation is to use the Maintainance and Security Center. The Information's Data tab and the Compact section may suggest that a compact be performed.

Commented by Pat BENSKY on September 13, 2022 at 1:55 AM
I'm a little confused by this. Example from the docs: If(Get table fragmentation(Table($i)->)>20) ToBeCompacted:=True End if But in my quick test, a table with no fragmentation returned 100, and a table with fragmentation returned 90. So it seems that the code should read: If(Get table fragmentation(Table($i)->)<80) ToBeCompacted:=True End if