mco_index_stat_get

Return statistics maintained for the specified index.

Prototype

    MCO_RET mco_index_stat_get(  /*IN*/ mco_trans_h t,
                                /*IN*/ uint2 index_number,
                                /*OUT*/ mco_index_stat_h stat);

Arguments

t
The mco_trans_h transaction handle returned by mco_trans_start().
index_number
A 2-byte unsigned integer representing the index for which statistics are desired. Normally, the total number of indexes is first obtained by calling mco_index_stat_num() then iterating from zero to the total number minus 1.
stat
The address of a mco_index_stat_t structure to receive the index statistics.

Description

This function returns statistics that are maintained for the index.

Note that compound (multi-segmented) indexes can be optimized by the database runtime. The maximum number of segments (fields) in the index that is subject to optimization is set through the MCO_MAX_INDEX_FIELD_SPEC in file mcocfg.h. The default value is 5. If the number of fields in the index exceeds the MCO_MAX_INDEX_FIELD_SPEC value, the access through the indexes not optimized. (For users with eXtremeDB source code, this value can be modified and libraries rebuilt. Note that increasing MCO_MAX_INDEX_FIELD_SPEC by one adds 16 bytes to the index header. Also note that the default setting adds 80 bytes to the index header.)

The application can determine whether an index has been optimized by calling mco_index_stat_get() which returns MCO_IDXST_FEATURE_OPTIMIZED as a value of the mco_index_stat_t::type.

Return Codes

MCO_S_OK
The index statistics were returned successfully.
MCO_E_INVALID_HANDLE
Database handle not opened.
MCO_E_INDEXLIMIT
Invalid index number.

Example

    Application snippet:

    const char * dbname = "SimpleDb";

    int main(int argc, char* argv[])
    {
        mco_db_h db;
        MCO_RET rc;
        mco_device_t dev;
        mco_db_params_t db_params;
        mco_trans_h t;
        uint2 n_indexes;
        mco_index_stat_t st;
        int j;

        ...
        rc = mco_db_open_dev(dbname, simple_get_dictionary(), &dev, 1, &db_params);
        if (MCO_S_OK != rc)
        {
            rc = mco_db_connect(dbname, &db);
            ...
            rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
            if (MCO_S_OK == rc)
            {
                mco_index_stat_num(t, &n_indexes);

                for (j = 0; j < n_indexes && MCO_S_OK == rc; j++)
                {
                    rc = mco_index_stat_get(t, j, &st);

                    if (MCO_S_OK == rc)
                    {
                        printf("%25s %4d key(s) %4d page(s)\n\t\t\t",
                            st.plabel, st.keys_num, st.pages_num);
                    }
                }
                ...
            }
        }
        ...
    }

Files

Header file:
mco.h
Source file:
mcodb.c
Library:
libmcolib.a