Documentation Home
MySQL NDB Cluster API Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 3.6Mb
PDF (A4) - 3.6Mb


2.3.8 The Index Class

This section provides information about the Index class.

Index Class Overview

Parent class

NdbDictionary

Child classes

None

Description

This class represents an index on an NDB Cluster table column. It is a descendant of the NdbDictionary class, using the Object class.

If you create or change indexes using the NDB API, these modifications cannot be seen by MySQL. The only exception to this is using Index::setName() to rename the index.

Methods

The following table lists the public methods of Index and the purpose or use of each method:

Table 2.23 Index class methods and descriptions

Name Description
Index() Class constructor
~Index() Destructor
addColumn() Adds a Column object to the index
addColumnName() Adds a column by name to the index
addColumnNames() Adds multiple columns by name to the index
getColumn() Gets a column making up (part of) the index
getLogging() Checks whether the index is logged to disk
getName() Gets the name of the index
getNoOfColumns() Gets the number of columns belonging to the index
getObjectStatus() Gets the index object status
getObjectVersion() Gets the index object status
getObjectId() Gets the index object ID
getTable() Gets the name of the table being indexed
getType() Gets the index type
setLogging() Enable/disable logging of the index to disk
setName() Sets the name of the index
setTable() Sets the name of the table to be indexed
setType() Set the index type

Types

Index defines one public type, the Type type.

Index Class Constructor

Description

This is used to create an new instance of Index.

Indexes created using the NDB API cannot be seen by the MySQL Server.

Signature
Index
    (
      const char* name = ""
    )
Parameters

The name of the new index. It is possible to create an index without a name, and then assign a name to it later using setName(). See Index::setName().

Return value

A new instance of Index.

Destructor

The destructor (~Index()) is supplied as a virtual method.

Index::addColumn()

Description

This method may be used to add a column to an index.

The order of the columns matches the order in which they are added to the index. However, this matters only with ordered indexes.

Signature
void addColumn
    (
      const Column& c
    )
Parameters

A reference c to the column which is to be added to the index.

Return value

None.

Index::addColumnName()

Description

This method works in the same way as addColumn(), except that it takes the name of the column as a parameter. See Index::getColumn().

Signature
void addColumnName
    (
      const char* name
    )
Parameters

The name of the column to be added to the index, as a constant character pointer.

Return value

None.

Index::addColumnNames()

Description

This method is used to add several column names to an index definition at one time.

As with the addColumn() and addColumnName() methods, the indexes are numbered in the order in which they were added. This normally matters only for ordered indexes.

Signature
void addColumnNames
    (
      unsigned     noOfNames,
      const char** names
    )
Parameters

This method takes two parameters, listed here:

  • The number of columns and names noOfNames to be added to the index.

  • The names to be added (as a pointer to a pointer).

Return value

None.

Index::getColumn()

Description

This method retrieves the column at the specified position within the index.

Signature
const Column* getColumn
    (
      unsigned no
    ) const
Parameters

The ordinal position number no of the column, as an unsigned integer. Use the getNoOfColumns() method to determine how many columns make up the index—see Index::getNoOfColumns(), for details.

Return value

The column having position no in the index, as a pointer to an instance of Column. See Section 2.3.1, “The Column Class”.

Index::getLogging()

Description

Use this method to determine whether logging to disk has been enabled for the index.

Indexes which are not logged are rebuilt when the cluster is started or restarted.

Ordered indexes currently do not support logging to disk; they are rebuilt each time the cluster is started. (This includes restarts.)

Signature
bool getLogging
    (
      void
    ) const
Parameters

None.

Return value

A Boolean value:

  • true: The index is being logged to disk.

  • false: The index is not being logged.

Index::getName()

Description

This method is used to obtain the name of an index.

Signature
const char* getName
    (
      void
    ) const
Parameters

None.

Return value

The name of the index, as a constant character pointer.

Index::getNoOfColumns()

Description

This method is used to obtain the number of columns making up the index.

Signature
unsigned getNoOfColumns
    (
      void
    ) const
Parameters

None.

Return value

An unsigned integer representing the number of columns in the index.

Index::getObjectStatus()

Description

This method gets the object status of the index.

Signature
virtual Object::Status getObjectStatus
    (
      void
    ) const
Parameters

None.

Return value

A Status value; see Object::Status, for more information.

Index::getObjectVersion()

Description

This method gets the object version of the index (see NDB Schema Object Versions).

Signature
virtual int getObjectVersion
    (
      void
    ) const
Parameters

None.

Return value

The object version for the index, as an integer.

Index::getObjectId()

Description

This method is used to obtain the object ID of the index.

Signature
virtual int getObjectId
    (
      void
    ) const
Parameters

None.

Return value

The object ID, as an integer.

Index::getTable()

Description

This method can be used to obtain the name of the table to which the index belongs.

Signature
const char* getTable
    (
      void
    ) const
Parameters

None.

Return value

The name of the table, as a constant character pointer.

Index::getType()

Description

This method can be used to find the type of index.

Signature
Type getType
    (
      void
    ) const
Parameters

None.

Return value

An index type. See Index::Type, for possible values.

Index::setLogging

Description

This method is used to enable or disable logging of the index to disk.

Signature
void setLogging
    (
      bool enable
    )
Parameters

setLogging() takes a single Boolean parameter enable. If enable is true, then logging is enabled for the index; if false, then logging of this index is disabled.

Return value

None.

Index::setName()

Description

This method sets the name of the index.

This is the only Index::set*() method whose result is visible to a MySQL Server.

Signature
void setName
    (
      const char* name
    )
Parameters

The desired name for the index, as a constant character pointer.

Return value

None.

Index::setTable()

Description

This method sets the table that is to be indexed. The table is referenced by name.

Signature
void setTable
    (
      const char* name
    )
Parameters

The name of the table to be indexed, as a constant character pointer.

Return value

None.

Index::setType()

Description

This method is used to set the index type.

Signature
void setType
    (
      Type type
    )
Parameters

The type of index. For possible values, see Index::Type.

Return value

None.

Index::Type

This section provides information about the Index type.

Description

This is an enumerated type which describes the sort of column index represented by a given instance of Index.

Do not confuse this enumerated type with Object::Type, or with Column::Type.

Enumeration values

Possible values are shown, along with descriptions, in the following table:

Table 2.24 Index::Type data type values and descriptions

Name Description
Undefined Undefined object type (initial/default value)
UniqueHashIndex Unique unordered hash index (only index type currently supported)
OrderedIndex Nonunique, ordered index