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


2.3.1 The Column Class

This section provides information about theColumn class, which models a column in anNDBCLUSTER table.

Column Class Overview

Parent class

NdbDictionary

Child classes

None

Description

Each instance ofColumn is characterized by its type, which is determined by a number of type specifiers:

  • Built-in type

  • Array length or maximum length

  • Precision and scale (currently not in use)

  • Character set (applicable only to columns using string data types)

  • Inline and part sizes (applicable only to blob columns)

These types in general correspond to MySQL data types and their variants. The data formats are same as in MySQL. The NDB API provides no support for constructing such formats; however, they are checked by theNDB kernel.

Methods

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

Table 2.6 Column class methods and descriptions

MethodDescription
Column()Class constructor; there is also a copy constructor
~Column()Class destructor
equal()ComparesColumn objects
getArrayType()Gets the column's array type
getAutoIncrement()Shows whether the column is auto-incrementing
getCharset()Get the character set used by a string (text) column (not applicable to columns not storing character data)
getColumnNo()Gets the column number
getDefaultValue()Returns the column's default value
getInlineSize()Gets the inline size of a blob column (not applicable to other column types)
getLength()Gets the column's length
getName()Gets the name of the column
getNullable()Checks whether the column can be set toNULL
getPartitionKey()Checks whether the column is part of the table's partitioning key
getPartSize()Gets the part size of a blob column (not applicable to other column types)
getPrecision()Gets the column's precision (used for decimal types only)
getPrimaryKey()Check whether the column is part of the table's primary key
getScale()Gets the column's scale (used for decimal types only)
getSize()Gets the size of an element
getSizeInBytesForRecord()Gets the space required for a column byNdbRecord, according to the column's type (added in NDB 7.4.7)
getStripeSize()Gets a BLOB column's stripe size (not applicable to other column types)
getStorageType()Gets the storage type used by this column
getType()Gets the column's type (Type value)
setArrayType()Sets the column'sArrayType
setAutoIncrement()Sets the column's auto-increment flag
setAutoIncrementInitialValue()Sets an auto-incrementing column's starting value
setCharset()Sets the character set used by a column containing character data (not applicable to nontextual columns)
setDefaultValue()Sets the column's default value
setInlineSize()Sets the inline size for a blob column (not applicable to columns not of blob types)
setLength()Sets the column's length
setName()Sets the column's name
setNullable()Toggles the column's nullability
setPartitionKey()Determines whether the column is part of the table's partitioning key
setPartSize()Sets the part size for a blob column (not applicable to columns not of blob types)
setPrecision()Sets the column's precision (used for decimal types only)
setPrimaryKey()Determines whether the column is part of the primary key
setScale()Sets the column's scale (used for decimal types only)
setStorageType()Sets the storage type to be used by this column
setStripeSize()Sets the stripe size for a blob column (not applicable to columns not of blob types)
setType()Sets the column'sType

Types

These are the public types of theColumn class:

Table 2.7 Column class types and descriptionse.

TypeDescription
ArrayTypeSpecifies the column's internal storage format
StorageTypeDetermines whether the column is stored in memory or on disk
TypeThe column's data type.NDB columns have the same data types as found in MySQL

The assignment (=) operator is overloaded for this class, so that it always performs a deep copy.

Important

Columns created using this class cannot be seen by the MySQL Server. This means that they cannot be accessed by MySQL clients, and that they cannot be replicated. For these reasons, it is often preferable to avoid working with them.

In the NDB API, column names are handled in case-sensitive fashion. (This differs from the MySQL C API.) To reduce the possibility for error, it is recommended that you name all columns consistently using uppercase or lowercase.

As with other database objects,Column object creation and attribute changes to existing columns done using the NDB API are not visible from MySQL. For example, if you change a column's data type usingColumn::setType(), MySQL will regard the type of column as being unchanged. The only exception to this rule with regard to columns is that you can change the name of an existing column usingColumn::setName().

Column::ArrayType

Abstract

This section provides information about theArrayType data type, which represents a column's internal attribute format.

Description

The attribute storage format can be either fixed or variable.

Enumeration values

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

Table 2.8 Column object ArrayType data type values and descriptions

NameDescription
ArrayTypeFixedstored as a fixed number of bytes
ArrayTypeShortVarstored as a variable number of bytes; uses 1 byte overhead
ArrayTypeMediumVarstored as a variable number of bytes; uses 2 bytes overhead

The fixed storage format is faster but also generally requires more space than the variable format. The default isArrayTypeShortVar forVar* types andArrayTypeFixed for others. The default is usually sufficient.

Column Constructor

Description

You can create a newColumn or copy an existing one using the class constructor.

AColumn created using the NDB API isnot visible to a MySQL server.

The NDB API handles column names in case-sensitive fashion. For example, if you create a column namedmyColumn, you will not be able to access it later usingMycolumn for the name. You can reduce the possibility for error, by naming all columns consistently using only uppercase or only lowercase.

Signature

You can create either a new instance of theColumn class, or by copying an existingColumn object. Both of these are shown here:

  • Constructor for a newColumn:

    Column    (      const char*name = ""    )

  • Copy constructor:

    Column    (      const Column&column    )
Parameters

When creating a new instance ofColumn, the constructor takes a single argument, which is the name of the new column to be created. The copy constructor also takes one parameter—in this case, a reference to theColumn instance to be copied.

Return value

AColumn object.

Destructor

TheColumn class destructor takes no arguments and returns nothing (void).

Column::equal()

Description

This method is used to compare oneColumn with another to determine whether the twoColumn objects are the same.

Signature
bool equal    (      const Column&column    ) const
Parameters

equal() takes a single parameter, a reference to an instance ofColumn.

Return value

true if the columns being compared are equal, otherwisefalse.

Column::getArrayType()

Description

This method gets the column's array type.

Signature
ArrayType getArrayType    (      void    ) const
Parameters

None.

Return value

AnArrayType; seeColumn::ArrayType for possible values.

Column::getAutoIncrement()

Description

This method shows whether the column is an auto-increment column.

Signature
bool getAutoIncrement    (      void    ) const
Parameters

None.

Return value

TRUE if the column is an auto-increment column,FALSE if it is not.

Column::getCharset()

Description

This gets the character set used by a text column.

This method is applicable only to columns whoseType value isChar,Varchar, orText.

The NDB API handles column names in case-sensitive fashion;myColumn andMycolumn are not considered to refer to the same column. It is recommended that you minimize the possibility of errors from using the wrong lettercase for column names by naming all columns consistently using only uppercase or only lowercase.

Signature
CHARSET_INFO* getCharset    (      void    ) const
Parameters

None.

Return value

A pointer to aCHARSET_INFO structure specifying both character set and collation. This is the same as a MySQLMY_CHARSET_INFO data structure; for more information, seemysql_get_character_set_info(),in the MySQL Manual.

Column::getColumnNo()

Description

This method gets the sequence number of a column within its containing table or index. If the column is part of an index (such as when returned bygetColumn()), it is mapped to its position within that index, and not within the table containing the index.

Signature
int getColumnNo    (      void    ) const
Parameters

None.

Return value

The column number as an integer.

Column::getDefaultValue()

Description

Gets a column's default value data.

To determine whether a table has any columns with default values, useTable::hasDefaultValues().

Signature
const void* getDefaultValue    (      unsigned int*len = 0    ) const
Parameters

len holds either the length of the default value data, or 0 in the event that the column is nullable or has no default value.

Return value

The default value data.

Column::getInlineSize()

Description

This method retrieves the inline size of a blob column—that is, the number of initial bytes to store in the table's blob attribute. This part is normally in main memory and can be indexed.

This method is applicable only to blob columns.

Beginning with NDB 8.0.29, you can also obtain this information in themysql client, by querying thendbinfo.blobs table.

Signature
int getInlineSize    (      void    ) const
Parameters

None.

Return value

The blob column's inline size, as an integer.

Column::getLength()

Description

This method gets the length of a column. This is either the array length for the column or—for a variable length array—the maximum length.

Signature
int getLength    (      void    ) const
Parameters

None.

Return value

The (maximum) array length of the column, as an integer.

Column::getName()

Description

This method returns the name of the column for which it is called.

The NDB API handles column names in case-sensitive fashion. For example, if you retrieve the namemyColumn for a given column, attempting to access this column usingMycolumn for the name fails with an error such asColumn is NULL orTable definition has undefined column. You can reduce the possibility for error, by naming all columns consistently using only uppercase or only lowercase.

Signature
const char* getName    (      void    ) const
Parameters

None.

Return value

The name of the column.

Column::getNullable()

Description

This method is used to determine whether the column can be set toNULL.

Signature
bool getNullable    (      void    ) const
Parameters

None.

Return value

A Boolean value:true if the column can be set toNULL, otherwisefalse.

Column::getPartitionKey()

Description

This method is used to check whether the column is part of the table's partitioning key.

Apartitioning key is a set of attributes used to distribute the tuples onto the data nodes. This key a hashing function specific to theNDB storage engine.

An example where this would be useful is an inventory tracking application involving multiple warehouses and regions, where it might be good to use the warehouse ID and district id as the partition key. This would place all data for a specific district and warehouse in the same storage node. Locally to each fragment the full primary key will still be used with the hashing algorithm in such a case.

For more information about partitioning, partitioning schemes, and partitioning keys in MySQL, seePartitioning, in the MySQL Manual.

The only type of user-defined partitioning that is supported for use with theNDB storage engine is key partitioning, including linear key partitioning.

Signature
bool getPartitionKey    (      void    ) const
Parameters

None.

Return value

true if the column is part of the partitioning key for the table, otherwisefalse.

Column::getPartSize()

Description

This method is used to get the blob part size of a BLOB column—that is, the number of bytes that are stored in each tuple of the blob table.

This method is applicable to BLOB columns only.

In NDB 8.0.29 and later, you can also obtain this information in themysql client or other MySQL client, by querying thendbinfo.blobs table.

Signature
int getPartSize    (      void    ) const
Parameters

None.

Return value

The column's part size, as an integer. In the case of aTinyblob column, this value is0 (that is, only inline bytes are stored).

Column::getPrecision()

Description

This method gets the precision of a column.

This method is applicable to decimal columns only.

Signature
int getPrecision    (      void    ) const
Parameters

None.

Return value

The column's precision, as an integer. The precision is defined as the number of significant digits; for more information, see the discussion of theDECIMAL data type inNumeric Data Types, in the MySQL Manual.

Column::getPrimaryKey()

Description

This method is used to determine whether the column is part of the table's primary key.

Signature
bool getPrimaryKey    (      void    ) const
Parameters

None.

Return value

A Boolean value:true if the column is part of the primary key of the table to which this column belongs, otherwisefalse.

Column::getScale()

Description

This method gets the scale used for a decimal column value.

This method is applicable to decimal columns only.

Signature
int getScale    (      void    ) const
Parameters

None.

Return value

The decimal column's scale, as an integer. The scale of a decimal column represents the number of digits that can be stored following the decimal point. It is possible for this value to be0. For more information, see the discussion of theDECIMAL data type inNumeric Data Types, in the MySQL Manual.

Column::getSize()

Description

This function is used to obtain the size of a column.

Signature
int getSize    (      void    ) const
Parameters

None.

Return value

The column's size in bytes (an integer value).

Column::getSizeInBytesForRecord()

Description

Gets the space required for a given column by anNdbRecord, depending on the column's type, as follows:

  • For a BLOB column, this value is the same assizeof(NdbRecord*), which is 4 or 8 bytes (the size of a pointer; platform-dependent).

  • For columns of all other types, it is the same as the value returned bygetSize().

This method was added in NDB NDB 7.4.7.

Signature
int getSizeInBytesForRecord    (      void    ) const
Parameters

None.

Return value

An integer (see Description).

Column::getStorageType()

Description

This method obtains a column's storage type.

Signature
StorageType getStorageType    (      void    ) const
Parameters

None.

Return value

AStorageType value; for more information about this type, seeColumn::StorageType.

Column::getStripeSize()

Description

This method gets the stripe size of a blob column—that is, the number of consecutive parts to store in each node group.

Signature
int getStripeSize    (      void    ) const
Parameters

None.

Return value

The column's stripe size, as an integer.

Column::getType()

Description

This method gets the column's data type.

Signature
Type getType    (      void    ) const
Parameters

None.

Return value

TheType (data type) of the column. For a list of possible values, seeColumn::Type.

Column::setArrayType()

Description

Sets the array type for the column.

Signature
void setArrayType    (      ArrayTypetype    )
Parameters

AColumn::ArrayType value. SeeColumn::ArrayType, for more information.

Return value

None.

Column::setAutoIncrement()

Description

Make the column auto-incrementing (or not).

Signature
void setAutoIncrement    (      boolflag    )
Parameters

A boolean value:TRUE to make the column auto-incrementing;FALSE to remove this property of the column.

Return value

None.

Column::setAutoIncrementInitialValue()

Description

Set the initial value for an auto-incrementing column.

Signature
void setAutoIncrementInitialValue    (      Uint64value    )
Parameters

The initial value for the column (a 64-bit integer).

Return value

None.

Column::setCharset()

Description

This method can be used to set the character set and collation of aChar,Varchar, orText column.

This method is applicable toChar,Varchar, andText columns only.

Changes made to columns using this method are not visible to MySQL.

Signature
void setCharset    (      CHARSET_INFO*cs    )
Parameters

This method takes one parameter.cs is a pointer to aCHARSET_INFO structure. For additional information, seeColumn::getCharset().

Return value

None.

Column::setDefaultValue()

Description

This method sets a column value to its default, if it has one; otherwise it sets the column toNULL.

To determine whether a table has any columns with default values, useTable::hasDefaultValues().

Signature
int setDefaultValue    (      const void*buf,      unsigned intlen    )
Parameters

This method takes 2 arguments: a value pointerbuf; and the lengthlen of the data, as the number of significant bytes. For fixed size types, this is the type size. For variable length types, the leading 1 or 2 bytes pointed to bybuffer also contain size information as normal for the type.

Return value

0 on success, 1 on failure..

Column::setInlineSize

Description

This method gets the inline size of a blob column—that is, the number of initial bytes to store in the table's blob attribute. This part is normally kept in main memory, and can be indexed and interpreted.

This method is applicable to blob columns only.

Changes made to columns using this method are not visible to MySQL. Beginning with NDB 8.0.30, you can change the inline size of a blob column in themysql client by settingBLOB_INLINE_SIZE in a column comment as part ofCREATE TABLE orALTER TABLE. SeeNDB_COLUMN Options, for more information.

Signature
void setInlineSize    (      intsize    )
Parameters

The integersize is the new inline size for the blob column.

Return value

None.

Column::setLength()

Description

This method sets the length of a column. For a variable-length array, this is the maximum length; otherwise it is the array length.

Changes made to columns using this method are not visible to MySQL.

Signature
void setLength    (      intlength    )
Parameters

This method takes a single argument—the integer valuelength is the new length for the column.

Return value

None.

Column::setName()

Description

This method is used to set the name of a column.

setName() is the onlyColumn method whose result is visible from a MySQL Server. MySQL cannot see any other changes made to existing columns using the NDB API.

Signature
void setName    (      const char*name    )
Parameters

This method takes a single argument—the new name for the column.

Return value

This methodNone.

Column::setNullable()

Description

This method toggles the nullability of a column.

Changes made to columns using this method are not visible to MySQL.

Signature
void setNullable    (      boolnullable    )
Parameters

A Boolean value. Usingtrue makes it possible to insertNULLs into the column; ifnullable isfalse, then this method performs the equivalent of changing the column toNOT NULL in MySQL.

Return value

None.

Column::setPartitionKey()

Description

This method makes it possible to add a column to the partitioning key of the table to which it belongs, or to remove the column from the table's partitioning key.

Changes made to columns using this method are not visible to MySQL.

For additional information, seeColumn::getPartitionKey().

Signature
void setPartitionKey    (      boolenable    )
Parameters

The single parameterenable is a Boolean value. Passingtrue to this method makes the column part of the table's partitioning key; ifenable isfalse, then the column is removed from the partitioning key.

Return value

None.

Column::setPartSize()

Description

This method sets the blob part size of a blob column—that is, the number of bytes to store in each tuple of the blob table.

This method is applicable to blob columns only.

Changes made to columns using this method are not visible to MySQL. You can increase the blob part size of a blob column to the maximum supported byNDB (13948) inmysql or another MySQL client by setting theMAX_BLOB_PART_SIZE option in a column comment as part of aCREATE TABLE orALTER TABLE statement. SeeNDB_COLUMN Options.

Signature
void setPartSize    (      intsize    )
Parameters

The integersize is the number of bytes to store in the blob table. Using zero for this value means only inline bytes can be stored, in effect making the column's typeTINYBLOB.

Return value

None.

Column::setPrecision()

Description

This method can be used to set the precision of a decimal column.

This method is applicable to decimal columns only.

Changes made to columns using this method are not visible to MySQL.

Signature
void setPrecision    (      intprecision    )
Parameters

This method takes a single parameter—precision is an integer, the value of the column's new precision. For additional information about decimal precision and scale, seeColumn::getPrecision(), andColumn::getScale().

Return value

None.

Column::setPrimaryKey()

Description

This method is used to make a column part of the table's primary key, or to remove it from the primary key.

Changes made to columns using this method are not visible to MySQL.

Signature
void setPrimaryKey    (      boolprimary    )
Parameters

This method takes a single Boolean value. If it istrue, then the column becomes part of the table's primary key; iffalse, then the column is removed from the primary key.

Return value

None.

Column::setScale()

Description

This method can be used to set the scale of a decimal column.

This method is applicable to decimal columns only.

Changes made to columns using this method are not visible to MySQL.

Signature
void setScale    (      intscale    )
Parameters

This method takes a single parameter—the integerscale is the new scale for the decimal column. For additional information about decimal precision and scale, seeColumn::getPrecision(), andColumn::getScale().

Return value

None.

Column::setStripeSize()

Description

This method sets the stripe size of a blob column—that is, the number of consecutive parts to store in each node group.

This method is applicable to blob columns only.

Changes made to columns using this method are not visible to MySQL.

Signature
void setStripeSize    (      intsize    )
Parameters

This method takes a single argument. The integersize is the new stripe size for the column.

Return value

None.

Column::setStorageType()

Description

Sets the storage type for the column.

Signature
void setStorageType    (      StorageTypetype    )
Parameters

AColumn::StorageType value. SeeColumn::StorageType, for more information.

Return value

None.

Column::setType()

Description

This method sets theType (data type) of a column.

setType() resets all column attributes to their (type dependent) default values; it should be the first method that you call when changing the attributes of a given column.

Changes made to columns using this method are not visible to MySQL.

Signature
void setType    (      Typetype    )
Parameters

This method takes a single parameter—the newColumn::Type for the column. The default isUnsigned. For a listing of all permitted values, seeColumn::Type.

Return value

None.

Column::StorageType

This section provides information about theStorageType data type, which describes the storage type used by aColumn object.

Description

The storage type used for a given column can be either in memory or on disk. Columns stored on disk mean that less RAM is required overall but such columns cannot be indexed, and are potentially much slower to access. The default isStorageTypeMemory.

Enumeration values

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

Table 2.9 Column object StorageType data type values and descriptions

NameDescription
StorageTypeMemoryStore the column in memory
StorageTypeDiskStore the column on disk

Column::Type

This section provides information about theType data type, which is used to describe a column's data type.

Description

Data types forColumn objects are analogous to the data types used by MySQL. The typesTinyint,Tinyintunsigned,Smallint,Smallunsigned,Mediumint,Mediumunsigned,Int,Unsigned,Bigint,Bigunsigned,Float, andDouble (that is, typesTinyint throughDouble in the order listed in the Enumeration Values table) can be used in arrays.

Do not confuseColumn::Type withObject::Type.

Enumeration values

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

Table 2.10 Column object Type data type values and descriptions

NameDescription
UndefinedUndefined
Tinyint1-byte signed integer
Tinyunsigned1-byte unsigned integer
Smallint2-byte signed integer
Smallunsigned2-byte unsigned integer
Mediumint3-byte signed integer
Mediumunsigned3-byte unsigned integer
Int4-byte signed integer
Unsigned4-byte unsigned integer
Bigint8-byte signed integer
Bigunsigned8-byte signed integer
Float4-byte float
Double8-byte float
OlddecimalSigned decimal as used prior to MySQL 5.0 (OBSOLETE)
OlddecimalunsignedUnsigned decimal as used prior to MySQL 5.0 (OBSOLETE)
DecimalSigned decimal as used by MySQL 5.0 and later
DecimalunsignedUnsigned decimal as used by MySQL 5.0 and later
CharA fixed-length array of 1-byte characters; maximum length is 255 characters
VarcharA variable-length array of 1-byte characters; maximum length is 255 characters
BinaryA fixed-length array of 1-byte binary characters; maximum length is 255 characters
VarbinaryA variable-length array of 1-byte binary characters; maximum length is 255 characters
DatetimeAn 8-byte date and time value, with a precision of 1 second (DEPRECATED)
Datetime2An 8-byte date and time value, with fractional seconds.
DateA 4-byte date value, with a precision of 1 day
BlobA binary large object; seeSection 2.3.13, “The NdbBlob Class”
TextA text blob
BitA bit value; the length specifies the number of bits
LongvarcharA 2-byteVarchar
LongvarbinaryA 2-byteVarbinary
TimeTime without date (DEPRECATED)
Time2Time without date, with fractional seconds.
Year1-byte year value in the range 1901-2155 (same as MySQL)
TimestampUnix time (DEPRECATED)
Timestamp2Unix time, with fractional seconds.

The NDB API provides access to time types with microseconds (TIME,DATETIME, andTIMESTAMP) asTime2,Datetime2, andTimestamp2. (Time,Datetime, andTimestamp are deprecated as of the same version.) UsesetPrecision() to set up to 6 fractional digits (default 0). Data formats are as in MySQL and must use the correct byte length.

SinceNDB can compare any of these values as binary strings, it does not perform any checks on the actual data.