Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Add a new index segment to an index (given the index handle and a field handle).


CTHANDLE ctdbAddSegment(CTHANDLE Handle, CTHANDLE FieldHandle,



ctdbAddSegment() adds a new index segment to an index, specifying both the field and the index by giving their handles. The operation of adding a segment to the index links the specified index with the specified field in its table. When a segment is added with this function, the segment is defined based on an individual full field of a table, using what is known as a record schema. In other words, instead of using a byte offset into the record structure and a length, all you need to provide is a handle to the field of interest. See the FairCom DB documentation for further information on record schemas.

Use ctdbAddSegmentByName() or ctdbAddSegmentByNbr() to add a segment given the index number. Use ctdbAddSegmentEx() to add a new extended index segment, that may use just part of the field as the index segment. Use ctdbInsSegment() to insert a segment in a specified position. Use ctdbDelSegment() to delete a segment from an index.

ctdbAddSegment() does the allocation of the index segment handle. After the segments, indexes, and fields have been defined, the table can be created or altered with ctdbCreateTable() or ctdbAlterTable(). Index segment handle deallocation is automatically handled by ctdbCloseTable() and ctdbCloseAll().

  • Handle [in] - the handle specifying the index which will receive the new segment.
  • FieldHandle [in] - the handle of the table field that will be used to build this segment.
  • SegMode [in] - the Index segment mode. The valid values for the segment modes are: CTSEG_SCHSEG, CTSEG_USCHSEG, CTSEG_VSCHSEG, CTSEG_UVSCHSEG, CTSEG_SCHSRL, described in c-treeDB API definitions. If used with a different segment mode, this call will return error 4047, meaning invalid segment mode. ctdbAddSegmentEx() accepts any segment mode.


ctdbAddSegment returns the segment handle on success, or NULL on failure.

When used on JSON fields, this function returns an error code of CTDBRET_NOTSUPPORTED.


pMyField0 = ctdbAddField(pMyTable, "Name", CT_FSTRING,32);

pMyField1 = ctdbAddField(pMyTable, "Balance", CT_SFLOAT, 4);

pMyIndex = ctdbAddIndex(pMyTable, "iName", CTINDEX_FIXED,NO,NO);

pMyIseg = ctdbAddSegment(pMyIndex, pMyField0, CTSEG_USCHSEG);

RetVal = ctdbCreateTable(pMyTable,"Table1",CTCREATE_NORMAL);

See also

ctdbAllocSegment(), ctdbAddSegmentByName(), ctdbAddSegmentByNbr(), ctdbAddSegmentEx(), ctdbInsSegment(), ctdbCreateTable(), ctdbAlterTable()