Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Calls the RBLIFILX() function to rebuild a c-tree table.


CTDBRET ctdbRebuildTable(CTHANDLE Handle, CTREBUILD_MODE mode);


  • Handle [IN] Table handle
  • mode [IN] The following modes are available:




    The normal rebuild mode.


    Purge duplicate records during rebuild.


    Update the IFIL structure in the table.


    Rebuild only the datafile.


    Compact and rebuild.


    (In V13 and later)

    Triggers a shared mode index rebuild (requires the table create mode CTCREATE_TRNLOG)

    CTREBUILD_ONLINE can be combined with CTREBUILD_COMPACT (that is, CTREBUILD_ONLINE|CTREBUILD_COMPACT) to perform an online version of the compact operation that runs while the files are open for update by other users. However, if the table does not use the CTCREATE_TRNLOG create mode, the online compact occurs but the indexes are not rebuilt.

Note: Exercise care when using CTREBUILD_DATAONLY and CTCREBUILD_UPDATEIFIL modes together as the index files will be removed from the table IFIL definition even if the index files still exist in the file system. This can cause later problems if ctdbAlterTable() is called to recreate the removed indexes.

ctdbRebuildTable() calls the FairCom DB RBLIFILX() function to rebuild a c-tree table. When used in conjunction with the open modes CTOPEN_CORRUPT and CTOPEN_DATAONLY, the ctdbRebuildTable() function can be used as a direct replacement for the c-tree ctrbldif rebuild utility.

The following steps are performed by c-treeDB during a table rebuild process:

  1. If a transaction is active, and the table being rebuilt was created with CTCREATE_TRNLOG or CTCREATE_PREIMG, the transaction is committed before the table is rebuilt, and the transaction is restarted after the table rebuild process is completed.
  2. The update corrupt flag, updflg, of the header of the data file is cleared.
  3. The internal delete stack chain of fixed-length data files or the internal delete management index of variable length data files are rebuilt.
  4. The existing index files are removed and new index files are rebuilt over the existing files, optimized for both size and speed.

You must open the table before ctdbRebuildTable() is executed. It is recommended that the table be opened with CTOPEN_EXCLUSIVE mode. If the table is corrupt, you will need to open the table with the CTOPEN_CORRUPT mode and then call ctdbRebuildTable() to rebuild the data and index files. If there are missing or corrupt index files, open the table with CTOPEN_DATAONLY mode and ctdbRebuildTable() will reconstruct the missing index files.

There may be situations when you need to invoke this function to rebuild only the data file. After the data file rebuild is successful, you may need to call ctdbRebuildTable() again to rebuild the index files.

Return Values


Symbolic Constant




Successful operation.



Duplicate keys purged and logged.

See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values.

See Also