Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic


Rebuilds a single index.

Short Name



ISAM function


COUNT RebuildIIndex(pIFIL ifilptr)


RebuildIIndex() rebuilds the indexes specified by ifilptr, starting with the file number specified in ifilptr->tfilno, producing new optimized indexes.

InitISAM() or InitISAMXtd() must be called prior to calling RebuildIIndex() and the file pointed to by ifilptr->tfilno must be open at the time of the call to RebuildIIndex().

RebuildIIndex() was created for use with PermIIndex() and TempIIndexXtd(). By default, both functions create and fill index files in one action. The ability to separate the index creation from the index build permits UpdateConditionalIndex() to set conditional expressions for the new indexes. If PermIIndex() is involved, the data file has its conditional index resource updated. If TempIIndexXtd() is involved, no permanent storage of the conditional index expression is made. The proper steps are:

  • PermIIndex() or TempIIndexXtd() with ifilptr->dxtdsiz == ctNO_IDX_BUILD.
  • UpdateConditionalIndex() for each new index with a conditional expression.
  • RebuildIIndex() for each new index.

Note: Between a call to PermIIndex() or TempIIndexXtd() and a call to RebuildIIndex(), the newly created indexes have remained opened, and have not been closed or closed and re-opened.

Note: The setting for SORT_MEMORY <n> in ctsrvr.cfg should be increased when rebuilding large indexes for performance. The closer SORT_MEMORY is set to the size of the index, the faster the sort phase of the rebuild will be, regardless of the index size. (There is no additional benefit in setting SORT_MEMORY larger than the size of the index.)


A zero (0) return indicates successful operation. A non-zero return indicates an error, check isam_err. The error returns are similar OpenCtFile() and RebuildIFile(). See c-tree Error Codes in the c-tree Programmer’s Reference Guide for a complete listing of valid c-tree error values.


extern IFIL customer;

COUNT retval;

FILNO filno;

COUNT conditional;

main() {

if (retval = InitISAM(10,10,16))

printf("\nInitISAM error = %d",retval);

filno = OpenFileWithResource(-1,"test", (ctEXCLUSIVE | ctPERMANENT));

if (filno < 0) {

printf("\nOpen failed");



customer->dfilno = filno

customer->tfilno = -1

if (conditional)

customer->dxtdsiz = ctNO_IDX_BUILD;

if (permIIndex(&customer))

printf("\nAdding Index failed (%d %d)", isam_err, isam_fil);

if (conditional && !(RebuildIIndex(&customer)))

printf("\nSuccessful compact");


printf("\nRebuildIIndex isam_err = %d",isam_err);




RebuildIIndex() does not support superfiles, see Superfiles in the c-tree Programmer’s Reference Guide.

RebuildIIndex() is not recommended for existing indexes. If one index becomes corrupt, FairCom recommend rebuilding all indexes associated with the data file.

See also

InitISAM(), InitISAMXtd(), UpdateConditionalIndex(), OpenCtFile(), PermIIndex(), RebuildIFile(), TempIIndexXtd()