MDX Indices

Chapter Updated 12/02/22


The objective of this chapter is to provide information regarding the basic concepts of how .MDX index files work in the Xbase environment.

The information in this chapter has been gathered by searching the internet and by examining the structure of known good

MDX Index File Characteristics

  • MDX files are the same name as the corresponding DBF file with an MDX extension.
  • MDX files are automatically opened by the library when the DBF file is opened.
  • MDX index files (aka prod indices) contain from one to 47 tags, where each tag has it's own key characteristics.
  • MDX indices maintain keys in either ascending or descending sort order.
  • MDX indices support filtered keys. For example, a filter of .NOT. DELETED() will keep deleted records out of the index tag.
  • MDX indices are automatically updated by the Xbase library after the indices are opened.
  • MDX indices support unique or non unique keys.

    Unique keys must be unique if the UniqueKeyOption is not set to XB_EMULATE_DBASE. If the UniqueKeyOption is set to XB_EMULATE_DBASE, then the database update routines will add a record to the table, but not add a corresponding duplicate key to the index tag. The UniqueKeyOption is off (don't allow duplicates) by default.

    Non-unique Keys are not required to be unique, duplicate keys are allowed if the index is created with the XB_NOT_UNIQUE setting. Duplicate keys are stored in record number order.

  • Character keys are left justified and padded on the right with spaces.
  • Numeric keys are stored as twelve byte BCD values.
  • Date keys are stored as eight byte double julian values.

    MDX File Internals

    The following information is not needed to use the library, it is just included for general information.

    MDX files are comprised of 512 pages where multiple pages make a block. The default setting is 1024 blocks, each block containing two pages.

    The first four pages contain:
  • Bytes 0 - 543 contain general file information.
  • Bytes 544 - 2047 is a 47 item table containing specific tag information.

    Pages five and beyound:
  • Bytes 2048 and beyond contain tag header blocks, interior nodes and leaf nodes.

    Interior and Leaf Nodes

    Interior Nodes and Leaf Nodes share the same structure in an NDX file with the exception that interior nodes have a non zero number immediately after the rightmost key on the node. Interior nodes point to other interior nodes or leaf nodes and leaf nodes point to records in a DBF file. Interior nodes are optional nodes in an MDX file, however if there are more than a few keys in the index there will certainly be one or more interior nodes in the file. There will always be at least one leaf node per tag in the file. Leaf nodes contain DBF record numbers which point to the location of the record in the DBF file.