Skip to content

DF_INDEX_LEVELS

See Also: Get_Attribute, Set_Attribute

The number of levels in the index.

Level

Index

Supported by

All Drivers

Type

Numeric, permanent

Access

Read only

Values

0 ~ maximum levels allowed per index for the database

Remarks

An index on a table is stored in a tree-like structure. The DF_INDEX_LEVELS attribute returns the number of levels in this tree.

This attribute is part of the basic set of attributes that must be supported by all drivers. However, it does not make any sense in some back ends. DataFlex SQL Drivers will return 0 (zero) for every table accessed; the Pervasive.SQL Driver will return -1 for every table accessed. Trying to set the attribute will be ignored.

The Embedded Database supports this attribute. For the Embedded Database, the attribute can be used to calculate the “real” maximum number of records in a table. See DF_FILE_MAX_RECORDS for a discussion of the “real” maximum.

Define C_MAXINDEXCAPACITY For |CI$00feffff

Function IndexCapacity Integer iKeylength Integer iLevels Returns Integer
    Integer iCapacity iBlocking
    Move (1024.0 / (iKeylength + 3)) To iBlocking
    Move (((iBlocking ^ iLevels) - 1) Min C_MAXINDEXCAPACITY) To iCapacity
    Function_Return iCapacity
End_Function

Function RealMaximum Handle hTable Returns Integer
    Integer iLastIndex iIndex iNumSegments iKeyLength iLevels iIndexCapacity iTableCapacity
    Move 0 To iTableCapacity
    Get_Attribute DF_FILE_LAST_INDEX_NUMBER Of hTable To iLastIndex

    For iIndex From 1 To iLastIndex
        Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments

        If (iNumSegments > 0) Begin
            Get_Attribute DF_INDEX_KEY_LENGTH Of hTable iIndex To iKeyLength
            Get_Attribute DF_INDEX_LEVELS Of hTable iIndex To iLevels
            Get IndexCapacity iKeyLength iLevels To iIndexCapacity

            If (iTableCapacity = 0 Or iTableCapacity > iIndexCapacity) ;
                Move iIndexCapacity To iTableCapacity
        End
    Loop

    Function_Return iTableCapacity
End_Function

The sample function above returns the real maximum number of records in an Embedded Database table.