Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Index segment modes

Each index segment has a "mode", which controls how that segment’s part of the index key is generated from the specified field / column of the associated table.

The segment modes are listed in Segment modes.

Preferred Segment Modes

Some of the segment modes are "preferred" because they maintain maximum compatibility and functionality.

These segment modes are based on the absolute field number in the data table (also known as schema fields). They use the entire field, rather than just part of a field. The preferred segment modes are:

  • CTSEG_SCHSEG
  • CTSEG_USCHSEG
  • CTSEG_VSCHSEG
  • CTSEG_UVSCHSEG
  • CTSEG_SCHSRL

Using the preferred segment modes makes c-treeDB API-based tables fully compatible with ISAM/Low-Level applications and/or FairCom DB SQL applications.

Sort Order

By default, the preferred segment modes sort in ascending order. This can be changed to descending sort order by OR’ing CTSEG_DESCENDING with the segment mode. If a custom sort order is desired, OR the segment mode with CTSEG_ALTSEG instead.

SCHSEG and Its Variants

When key segment mode SCHSEG or any of its variants (USCHSEG, VSCHSEG, or UVSCHSEG) is used, the interpretation of the data is based on the underlying type found in the schema.

The use of VSCHSEG instead of SCHSEG is rather subtle:

If a fixed-length field has a field delimiter or a length count, specifying VSCHSEG indicates that if the actual data is shorter than the segment length, pad the contents out to the full segment length. The default padding is an ASCII space character, but the ctdbSetPadChar() function can be used to change the padding and field delimiter characters for fixed-length string fields.

If SCHSEG is used instead, then delimiters or length counts will not be used to determine how to pad the key segment. Whatever is in the fixed-length field will be used; even if it causes "garbage" to be used beyond the actual contents. Of course, if a fixed-length field is carefully pre-filled or padded, then the use of SCHSEG will not cause any problem.

You may OR in the mode CTSEG_DESCENDING to the segment mode to specify the descending sort order for a segment. You can also OR in the segment mode CTSEG_ALTSEG to specify an alternate collating sequence for the segment. Both of these modifications can be used at the same time, and apply to the individual segment, and not to the entire key.

Key segment mode SCHSEG is used when the segment links to an auto-increment field / column in the data table.

TOCIndex