MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbSchemaOp Class Reference

Represents various operations for use in schema transactions. More...

#include <NdbSchemaOp.hpp>

Collaboration diagram for NdbSchemaOp:

Public Member Functions

int createTable (const char *aTableName, Uint32 aTableSize=8, KeyType aTupleKey=TupleKey, int aNrOfPages=2, FragmentType aFragmentType=All, int aKValue=6, int aMinLoadFactor=78, int aMaxLoadFactor=80, int aMemoryType=1, bool aStoredTable=true)
int createTable (const char *aTableName, Uint32 aTableSize, KeyType aTupleKey, int aNrOfPages, FragmentType aFragmentType, int aKValue, int aMinLoadFactor, int aMaxLoadFactor, int aMemoryType, int aStoredTable)
int createAttribute (const char *aAttrName, KeyType aTupleKey=NoKey, int aAttrSize=32, int aArraySize=1, AttrType aAttrType=UnSigned, StorageMode aStorageMode=MMBased, bool nullable=false, int aStType=0, int aDistributionKey=0, int aDistributionGroup=0, int aDistributionGroupNoOfBits=16, bool aAutoIncrement=false, const char *aDefaultValue=0)
int createAttribute (const char *aAttrName, KeyType aTupleKey, int aAttrSize, int aArraySize, AttrType aAttrType, StorageMode aStorageMode, NullAttributeType aNullAttr, int aStType, int aDistributionKey=0, int aDistributionGroup=0, int aDistributionGroupNoOfBits=16)
const NdbErrorgetNdbError () const

Protected Member Functions

 NdbSchemaOp (Ndb *aNdb)
void release ()
int sendRec ()
int sendSignals (Uint32 aNodeId, bool HaveMutex)
int init (NdbSchemaCon *aSchemaCon)

Protected Attributes

NdbtheNdb
NdbSchemaContheSchemaCon
class NdbDictionary::Tablem_currentTable

Friends

class Ndb
class NdbSchemaCon

Detailed Description

Represents various operations for use in schema transactions.

This class is used for schema operations, e.g. creating tables and attributes.

The NdbSchemaOp object is created using NdbSchemaCon::getNdbSchemaOp.

Note
This class is deprecated and is now replaced with the class NdbDictionary.

Definition at line 130 of file NdbSchemaOp.hpp.

Member Function Documentation

int NdbSchemaOp::createAttribute ( const char *  aAttrName,
KeyType  aTupleKey = NoKey,
int  aAttrSize = 32,
int  aArraySize = 1,
AttrType  aAttrType = UnSigned,
StorageMode  aStorageMode = MMBased,
bool  nullable = false,
int  aStType = 0,
int  aDistributionKey = 0,
int  aDistributionGroup = 0,
int  aDistributionGroupNoOfBits = 16,
bool  aAutoIncrement = false,
const char *  aDefaultValue = 0 
)

Add a new attribute to a database table.

Attributes can only be added to a table in the same transaction as the transaction creating the table.

Note
The NdbSchemaCon transaction should be closed with Ndb::closeSchemaTransaction, even if this method fails.

Example creating an unsigned int attribute belonging to the primary key of the table it is created in:

MySchemaOp->createAttribute("Attr1", // Attribute name
TupleKey, // Belongs to primary key
32, // 32 bits
1, // Not an array attribute
UnSigned, // Unsigned type
);

Example creating a string attribute belonging to the primary key of the table it is created in:

MySchemaOp->createAttribute("Attr1", // Attribute name
TupleKey, // Belongs to primary key
8, // Each character is 8 bits
12, // Max 12 chars in string
String, // Attribute if of type string
);

A distribution key is a set of attributes which are used to distribute the tuples onto the NDB nodes. A distribution group is a part (currently 16 bits) of an attribute used to distribute the tuples onto the NDB nodes. The distribution key uses the NDB Cluster hashing function, while the distribution group uses a simpler function.

Parameters
aAttrNameAttribute name. Should not be NULL.
aTupleKeyThis parameter specifies whether the attribute is part of the primary key or not. Floats are not allowed in the primary key.
Legal values: NoKey, TupleKey
aAttrSizeSpecifies the size of the elements of the attribute. (An attribute can consist of an array of elements.)
Legal values: 8, 16, 32, 64 and 128 bits.
aArraySizeSize of array.
Legal values: 0 = variable-sized array, 1 = no array, and 2- = fixed size array.
Variable-sized array attributes are not yet supported.
There is no upper limit of the array size for a single attribute.
aAttrTypeThe attribute type. This is only of interest if calculations are made within NDB.
Legal values: UnSigned, Signed, Float, String
aStorageModeMain memory based or disk based attribute.
Legal values: MMBased, DiskBased
Disk-based attributes are not yet supported.
nullableSet to true if NULL is a correct value for the attribute.
Legal values: true, false
aStTypeObsolete since wl-2066
aDistributionKeySometimes it is preferable to use a subset of the primary key as the distribution key. An example is TPC-C where it might be good to use the warehouse id and district id as the distribution key.
Locally in the fragments the full primary key will still be used with the hashing algorithm. Set to 1 if this attribute is part of the distribution key. All distribution key attributes must be defined before any other attributes are defined.
aDistributionGroupIn other applications it is desirable to use only a part of an attribute to create the distribution key. This is applicable for some telecom applications.
In these situations one must provide how many bits of the attribute that is to be used as the distribution hash value.
This provides some control to the application of the distribution. It still needs to be part of a primary key the attribute and must be defined as the first attribute.
aDistributionGroupNoOfBitsNumber of bits to use of the distribution group attribute in the distribution hash value.
Currently, only 16 bits is supported. It will always be the last 16 bits in the attribute which is used for the distribution group.
aAutoIncrementSet to autoincrement attribute.
aDefaultValueSet a default value of attribute.
Returns
Returns 0 when successful and returns -1 otherwise.

Definition at line 111 of file NdbSchemaOp.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int NdbSchemaOp::createAttribute ( const char *  aAttrName,
KeyType  aTupleKey,
int  aAttrSize,
int  aArraySize,
AttrType  aAttrType,
StorageMode  aStorageMode,
NullAttributeType  aNullAttr,
int  aStType,
int  aDistributionKey = 0,
int  aDistributionGroup = 0,
int  aDistributionGroupNoOfBits = 16 
)
inline
Deprecated:
do not use!

Definition at line 445 of file NdbSchemaOp.hpp.

Here is the call graph for this function:

int NdbSchemaOp::createTable ( const char *  aTableName,
Uint32  aTableSize = 8,
KeyType  aTupleKey = TupleKey,
int  aNrOfPages = 2,
FragmentType  aFragmentType = All,
int  aKValue = 6,
int  aMinLoadFactor = 78,
int  aMaxLoadFactor = 80,
int  aMemoryType = 1,
bool  aStoredTable = true 
)

Create a new table in the database.

Note
The NdbSchemaCon should be closed with Ndb::closeSchemaTransaction, even if this method fails.
Parameters
aTableNameTable name. Should not be NULL.
aTableSize(Performance parameter.) Initial size of the data part of the table expressed in kByte. The database handles bad parameter setting but at a certain loss in performance. The size given here is the initial size allocated for the table storage (the data part). When calculating the data storage one should add the size of all attributes (each attribute consumes at least 4 bytes) and also an overhead of 12 byte. Variable size attributes (not supported yet) will have a size of 12 bytes plus the actual data storage parts where there is an additional overhead based on the size of the variable part.
An example table with 5 attributes: one 64 bit attribute, one 32 bit attribute, two 16 bit attributes and one array of 64 8 bits. This table will consume 12 (overhead) + 8 + 4 + 2*4 (4 is minimum) + 64 = 96 bytes per record. Additionally an overhead of about 2 % as page headers and waste should be allocated. Thus, 1 million records should consume 96 MBytes plus the overhead 2 MByte and rounded up to 100 000 kBytes.
This parameter is currently not used.
aTupleKeyIndicates if the table has a primary key or not.
TupleKey means that a primary key consisting of one to four attributes (at most one of variable size) uniquely identifies each record in the created table.
TupleId means that a tuple identity is used. The tuple identity is a unique key indentifying each record of the created table. The tuple identity is a (non-stored) 64 bit attribute named NDB$TID.
When inserting a record (tuple), the method NdbOperation::setTupleId will generate a unique tuple identity and return it to the user.
When reading, updating or deleting a record in a table with TupleId, NdbOperation::equal("NDB$TID", value_Uint64) can be used to identify the record.
Legal values: TupleKey or TupleId.
aNrOfPages(Performance parameter.) Specifies the initial size of the index storage. When calculating the index storage, each key has approximately 14 byte of overhead plus the size of the key. Each key attribute takes up at least 4 bytes of storage. Thus a mixed key consisting of a 64 bit attribute, a 32 bit attribute and a 16 bit attribute will consume approx. 30 bytes per key. Thus, the if initial size is to be 1 million rows, then aNrOfPages should be set to 30 M / 8k = 2670 pages.
This parameter is currently not used.
aFragmentTypeType of fragmentation.
All (default) means that the table fragments are automatically distributed on all nodes in the system.
DistributionGroup and DistributionKey are also supported. For further details about these types see the documentation of Ndb::startTransaction.
aKValue(Hash parameter.) Only allowed value is 6. Later implementations might add flexibility in this parameter.
aMinLoadFactor(Hash parameter.) This value specifies the load factor when starting to shrink the hash table. It must be smaller than aMaxLoadFactor. Both these factors are given in percentage.
aMaxLoadFactor(Hash parameter.) This value specifies the load factor when starting to split the containers in the local hash tables. 100 is the maximum which will optimize memory usage (this is the figure used for the above calculations). A lower figure will store less information in each container and thus find the key faster but consume more memory.
aMemoryTypeCurrently only 1 is allowed which specifies storage of table in main memory. Later 2 will be added where the table is stored completely on disk and 3 where the index is in main memory but data is on disk. If 1 is chosen an individual attribute can still be specified as a disk attribute.
aStoredTableIf set to false it indicates that the table is a temporary table and should not be logged to disk. In case of a system restart the table will still be defined and exist but will be empty. Thus no checkpointing and no logging is performed on the table. The default value is true and indicates a normal table with full checkpointing and logging activated.
Returns
Returns 0 when successful and returns -1 otherwise.

Definition at line 74 of file NdbSchemaOp.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int NdbSchemaOp::createTable ( const char *  aTableName,
Uint32  aTableSize,
KeyType  aTupleKey,
int  aNrOfPages,
FragmentType  aFragmentType,
int  aKValue,
int  aMinLoadFactor,
int  aMaxLoadFactor,
int  aMemoryType,
int  aStoredTable 
)
inline

This is the old function declaration, don't use.

Deprecated:
do not use!

Definition at line 285 of file NdbSchemaOp.hpp.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class Ndb
friend

Reciver(s)

Definition at line 132 of file NdbSchemaOp.hpp.


The documentation for this class was generated from the following files: