KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Quickly checking for table fragmentation
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: August 8, 2013

Here is a quick method for checking the table fragmentation of a database:

C_LONGINT($tables_l;$i;$a)
C_TIME($fileRef)
C_TEXT($crlf)
C_LONGINT($frag_l)

$tables_l:=Get last table number
ARRAY TEXT($tablesNames_at;$tables_l)
ARRAY LONGINT($tableRecs_al;$tables_l)
ARRAY LONGINT($tableFrag_al;$tables_l)

For ($i;1;$tables_l)
   If (Is table number valid($i))
      $frag_l:=Get table fragmentation(Table($i)->)
      $tablesNames_at{$i}:=Table name($i)
      $tableRecs_al{$i}:=Records in table(Table($i)->)
      $tableFrag_al{$i}:=$frag_l
   Else
      $tablesNames_at{$i}:="N/A"
      $tableFrag_al{$i}:=0
      $tableRecs_al{$i}:=0
   End if
End for

// export to file
$fileRef:=Create document(Get 4D folder(Database Folder)+"fragmentation.csv")
$crlf:=Char(Carriage return)+Char(Line feed)
SEND PACKET($fileRef;"Table #"+Char(Tab)+"Table Name"+Char(Tab)+"Fragmentation"+Char(Tab)+"Records Found"+$crlf)
For ($a;1;$tables_l)
   SEND PACKET($fileRef;String($a)+Char(Tab)+$tablesNames_at{$a}+Char(Tab)+\
   String($tableFrag_al{$a})+Char(Tab)+String($tableRecs_al{$a})+$crlf)
End for
CLOSE DOCUMENT($fileRef)

SHOW ON DISK(Get 4D folder(Database Folder)+"fragmentation.csv")


The code above generates a tab delimited document and places the it next to the structure file. The tab delimited document specifies the following information:

Table #      Table Name      Fragmentation      Records Found

See Also: