partly rewritten the Diciotnary docs to reflect the integration with MySQL

This commit is contained in:
tomas@poseidon.ndb.mysql.com 2004-12-23 17:29:48 +01:00
parent 61e8a8ddbf
commit 59fadbcba7

View file

@ -14,18 +14,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*****************************************************************************
* Name: NdbDictionary.hpp
* Include:
* Link:
* Author: Jonas Oreland
* Date: 2003-05-14
* Version: 0.1
* Description: Data dictionary support
* Documentation:
* Adjust: 2003-05-14 Jonas Oreland First version.
****************************************************************************/
#ifndef NdbDictionary_H
#define NdbDictionary_H
@ -39,11 +27,15 @@ typedef struct charset_info_st CHARSET_INFO;
* @class NdbDictionary
* @brief Data dictionary class
*
* This class supports all schema data definition and enquiry such as:
* -# Creating tables (Dictionary::createTable) and table columns
* -# Dropping tables (Dictionary::dropTable)
* -# Creating secondary indexes (Dictionary::createIndex)
* -# Dropping secondary indexes (Dictionary::dropIndex)
* The preferred and supported way to create tables and indexes
* in ndb is through the
* MySQL Server (see MySQL reference Manual, section MySQL Cluster).
*
* Tables and indexes that are created directly through the
* NdbDictionary class
* can not be viewed from the MySQL Server.
*
* This class supports schema data enquiries such as:
* -# Enquiries about tables
* (Dictionary::getTable, Table::getNoOfColumns,
* Table::getPrimaryKey, and Table::getNoOfPrimaryKeys)
@ -51,7 +43,13 @@ typedef struct charset_info_st CHARSET_INFO;
* (Dictionary::getIndex, Index::getNoOfColumns,
* and Index::getColumn)
*
* NdbDictionary has several help (inner) classes:
* This class supports schema data definition such as:
* -# Creating tables (Dictionary::createTable) and table columns
* -# Dropping tables (Dictionary::dropTable)
* -# Creating secondary indexes (Dictionary::createIndex)
* -# Dropping secondary indexes (Dictionary::dropIndex)
*
* NdbDictionary has several help (inner) classes to support this:
* -# NdbDictionary::Table for creating tables
* -# NdbDictionary::Column for creating table columns
* -# NdbDictionary::Index for creating secondary indexes
@ -195,6 +193,130 @@ public:
* @name General
* @{
*/
/**
* Get name of column
* @return Name of the column
*/
const char* getName() const;
/**
* Get if the column is nullable or not
*/
bool getNullable() const;
/**
* Check if column is part of primary key
*/
bool getPrimaryKey() const;
/**
* Get number of column (horizontal position within table)
*/
int getColumnNo() const;
/**
* Check if column is equal to some other column
* @param column Column to compare with
* @return true if column is equal to some other column otherwise false.
*/
bool equal(const Column& column) const;
/** @} *******************************************************************/
/**
* @name Get Type Specifiers
* @{
*/
/**
* Get type of column
*/
Type getType() const;
/**
* Get precision of column.
* @note Only applicable for builtin type Decimal
*/
int getPrecision() const;
/**
* Get scale of column.
* @note Only applicable for builtin type Decimal
*/
int getScale() const;
/**
* Get length for column
* Array length for column or max length for variable length arrays.
*/
int getLength() const;
/**
* For Char or Varchar or Text, get MySQL CHARSET_INFO. This
* specifies both character set and collation. See get_charset()
* etc in MySQL. (The cs is not "const" in MySQL).
*/
CHARSET_INFO* getCharset() const;
/**
* For blob, get "inline size" i.e. number of initial bytes
* to store in table's blob attribute. This part is normally in
* main memory and can be indexed and interpreted.
*/
int getInlineSize() const;
/**
* For blob, get "part size" i.e. number of bytes to store in
* each tuple of the "blob table". Can be set to zero to omit parts
* and to allow only inline bytes ("tinyblob").
*/
int getPartSize() const;
/**
* For blob, set or get "stripe size" i.e. number of consecutive
* <em>parts</em> to store in each node group.
*/
int getStripeSize() const;
/**
* Get size of element
*/
int getSize() const;
/**
* Check if column is part of distribution key
*
* A <em>distribution key</em> is a set of attributes which are used
* to distribute the tuples onto the NDB nodes.
* The distribution key uses the NDB Cluster hashing function.
*
* An example where this is useful is TPC-C where it might be
* good to use the warehouse id and district id as the distribution key.
* This would place all data for a specific district and warehouse
* in the same database node.
*
* Locally in the fragments the full primary key
* will still be used with the hashing algorithm.
*
* @return true then the column is part of
* the distribution key.
*/
bool getDistributionKey() const;
/** @} *******************************************************************/
/**
* @name Column creation
* @{
*
* These operations should normally not be performed in an NbdApi program
* as results will not be visable in the MySQL Server
*
*/
/**
* Constructor
* @param name Name of column
@ -213,50 +335,16 @@ public:
*/
void setName(const char * name);
/**
* Get name of column
* @return Name of the column
*/
const char* getName() const;
/**
* Set whether column is nullable or not
*/
void setNullable(bool);
/**
* Get if the column is nullable or not
*/
bool getNullable() const;
/**
* Set that column is part of primary key
*/
void setPrimaryKey(bool);
/**
* Check if column is part of primary key
*/
bool getPrimaryKey() const;
/**
* Get number of column (horizontal position within table)
*/
int getColumnNo() const;
/**
* Check if column is equal to some other column
* @param column Column to compare with
* @return true if column is equal to some other column otherwise false.
*/
bool equal(const Column& column) const;
/** @} *******************************************************************/
/**
* @name Type Specifiers
* @{
*/
/**
* Set type of column
* @param type Type of column
@ -267,35 +355,18 @@ public:
*/
void setType(Type type);
/**
* Get type of column
*/
Type getType() const;
/**
* Set precision of column.
* @note Only applicable for builtin type Decimal
*/
void setPrecision(int);
/**
* Get precision of column.
* @note Only applicable for builtin type Decimal
*/
int getPrecision() const;
/**
* Set scale of column.
* @note Only applicable for builtin type Decimal
*/
void setScale(int);
/**
* Get scale of column.
* @note Only applicable for builtin type Decimal
*/
int getScale() const;
/**
* Set length for column
* Array length for column or max length for variable length arrays.
@ -303,72 +374,41 @@ public:
void setLength(int length);
/**
* Get length for column
* Array length for column or max length for variable length arrays.
*/
int getLength() const;
/**
* For Char or Varchar or Text, set or get MySQL CHARSET_INFO. This
* For Char or Varchar or Text, get MySQL CHARSET_INFO. This
* specifies both character set and collation. See get_charset()
* etc in MySQL. (The cs is not "const" in MySQL).
*/
void setCharset(CHARSET_INFO* cs);
CHARSET_INFO* getCharset() const;
/**
* For blob, set or get "inline size" i.e. number of initial bytes
* For blob, get "inline size" i.e. number of initial bytes
* to store in table's blob attribute. This part is normally in
* main memory and can be indexed and interpreted.
*/
void setInlineSize(int size);
int getInlineSize() const;
/**
* For blob, set or get "part size" i.e. number of bytes to store in
* For blob, get "part size" i.e. number of bytes to store in
* each tuple of the "blob table". Can be set to zero to omit parts
* and to allow only inline bytes ("tinyblob").
*/
void setPartSize(int size);
int getPartSize() const;
/**
* For blob, set or get "stripe size" i.e. number of consecutive
* For blob, get "stripe size" i.e. number of consecutive
* <em>parts</em> to store in each node group.
*/
void setStripeSize(int size);
int getStripeSize() const;
/**
* Get size of element
*/
int getSize() const;
/**
* Set distribution key
*
* A <em>distribution key</em> is a set of attributes which are used
* to distribute the tuples onto the NDB nodes.
* The distribution key uses the NDB Cluster hashing function.
*
* An example where this is useful is TPC-C where it might be
* good to use the warehouse id and district id as the distribution key.
* This would place all data for a specific district and warehouse
* in the same database node.
*
* Locally in the fragments the full primary key
* will still be used with the hashing algorithm.
* @see getDistributionKey
*
* @param enable If set to true, then the column will be part of
* the distribution key.
*/
void setDistributionKey(bool enable);
/**
* Check if column is part of distribution key
* @see setDistributionKey
*/
bool getDistributionKey() const;
/** @} *******************************************************************/
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
@ -429,30 +469,6 @@ public:
* @name General
* @{
*/
/**
* Constructor
* @param name Name of table
*/
Table(const char * name = "");
/**
* Copy constructor
* @param table Table to be copied
*/
Table(const Table& table);
virtual ~Table();
/**
* Assignment operator, deep copy
* @param table Table to be copied
*/
Table& operator=(const Table&);
/**
* Name of table
* @param name Name of table
*/
void setName(const char * name);
/**
* Get table name
@ -464,12 +480,6 @@ public:
*/
int getTableId() const;
/**
* Add a column definition to a table
* @note creates a copy
*/
void addColumn(const Column &);
/**
* Get column definition via name.
* @return null if none existing name
@ -511,30 +521,13 @@ public:
* The default value is true and indicates a normal table
* with full checkpointing and logging activated.
*/
void setLogging(bool);
/**
* @see NdbDictionary::Table::setLogging.
*/
bool getLogging() const;
/**
* Set fragmentation type
*/
void setFragmentType(FragmentType);
/**
* Get fragmentation type
*/
FragmentType getFragmentType() const;
/**
* Set KValue (Hash parameter.)
* Only allowed value is 6.
* Later implementations might add flexibility in this parameter.
*/
void setKValue(int kValue);
/**
* Get KValue (Hash parameter.)
* Only allowed value is 6.
@ -542,15 +535,6 @@ public:
*/
int getKValue() const;
/**
* Set MinLoadFactor (Hash parameter.)
* This value specifies the load factor when starting to shrink
* the hash table.
* It must be smaller than MaxLoadFactor.
* Both these factors are given in percentage.
*/
void setMinLoadFactor(int);
/**
* Get MinLoadFactor (Hash parameter.)
* This value specifies the load factor when starting to shrink
@ -560,16 +544,6 @@ public:
*/
int getMinLoadFactor() const;
/**
* Set MaxLoadFactor (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.
* A lower figure will store less information in each container and thus
* find the key faster but consume more memory.
*/
void setMaxLoadFactor(int);
/**
* Get MaxLoadFactor (Hash parameter.)
* This value specifies the load factor when starting to split
@ -612,15 +586,83 @@ public:
const void* getFrmData() const;
Uint32 getFrmLength() const;
/**
* Set frm file to store with this table
*/
void setFrm(const void* data, Uint32 len);
/** @} *******************************************************************/
/**
* Set table object type
* @name Table creation
* @{
*
* These methods should normally not be used in an application as
* the result is not accessible from the MySQL Server
*
*/
void setObjectType(Object::Type type);
/**
* Constructor
* @param name Name of table
*/
Table(const char * name = "");
/**
* Copy constructor
* @param table Table to be copied
*/
Table(const Table& table);
virtual ~Table();
/**
* Assignment operator, deep copy
* @param table Table to be copied
*/
Table& operator=(const Table&);
/**
* Name of table
* @param name Name of table
*/
void setName(const char * name);
/**
* Add a column definition to a table
* @note creates a copy
*/
void addColumn(const Column &);
/**
* @see NdbDictionary::Table::getLogging.
*/
void setLogging(bool);
/**
* Set fragmentation type
*/
void setFragmentType(FragmentType);
/**
* Set KValue (Hash parameter.)
* Only allowed value is 6.
* Later implementations might add flexibility in this parameter.
*/
void setKValue(int kValue);
/**
* Set MinLoadFactor (Hash parameter.)
* This value specifies the load factor when starting to shrink
* the hash table.
* It must be smaller than MaxLoadFactor.
* Both these factors are given in percentage.
*/
void setMinLoadFactor(int);
/**
* Set MaxLoadFactor (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.
* A lower figure will store less information in each container and thus
* find the key faster but consume more memory.
*/
void setMaxLoadFactor(int);
/**
* Get table object type
@ -637,6 +679,16 @@ public:
*/
virtual int getObjectVersion() const;
/**
* Set frm file to store with this table
*/
void setFrm(const void* data, Uint32 len);
/**
* Set table object type
*/
void setObjectType(Object::Type type);
/** @} *******************************************************************/
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
@ -661,28 +713,17 @@ public:
*/
class Index : public Object {
public:
/**
* Constructor
* @param name Name of index
*/
Index(const char * name = "");
virtual ~Index();
/**
* Set the name of an index
* @name Getting Index properties
* @{
*/
void setName(const char * name);
/**
* Get the name of an index
*/
const char * getName() const;
/**
* Define the name of the table to be indexed
*/
void setTable(const char * name);
/**
* Get the name of the table being indexed
*/
@ -714,6 +755,69 @@ public:
const char * getIndexColumn(int no) const ;
#endif
/**
* Represents type of index
*/
enum Type {
Undefined = 0, ///< Undefined object type (initial value)
UniqueHashIndex = 3, ///< Unique un-ordered hash index
///< (only one currently supported)
OrderedIndex = 6 ///< Non-unique ordered index
};
/**
* Get index type of the index
*/
Type getType() const;
/**
* Check if index is set to be stored on disk
*
* @return if true then logging id enabled
*
* @note Non-logged indexes are rebuilt at system restart.
* @note Ordered index does not currently support logging.
*/
bool getLogging() const;
/**
* Get object status
*/
virtual Object::Status getObjectStatus() const;
/**
* Get object version
*/
virtual int getObjectVersion() const;
/** @} *******************************************************************/
/**
* @name Index creation
* @{
*
* These methods should normally not be used in an application as
* the result will not be visible from the MySQL Server
*
*/
/**
* Constructor
* @param name Name of index
*/
Index(const char * name = "");
virtual ~Index();
/**
* Set the name of an index
*/
void setName(const char * name);
/**
* Define the name of the table to be indexed
*/
void setTable(const char * name);
/**
* Add a column to the index definition
* Note that the order of columns will be in
@ -755,59 +859,26 @@ public:
void addIndexColumns(int noOfNames, const char ** names);
#endif
/**
* Represents type of index
*/
enum Type {
Undefined = 0, ///< Undefined object type (initial value)
UniqueHashIndex = 3, ///< Unique un-ordered hash index
///< (only one currently supported)
OrderedIndex = 6 ///< Non-unique ordered index
};
/**
* Set index type of the index
*/
void setType(Type type);
/**
* Get index type of the index
*/
Type getType() const;
/**
* Enable/Disable index storage on disk
*
* @param enable If enable is set to true, then logging becomes enabled
*
* @see NdbDictionary::Table::setLogging
*
* @note Non-logged indexes are rebuilt at system restart.
* @note Ordered index does not currently support logging.
* @see NdbDictionary::Index::getLogging
*/
void setLogging(bool enable);
/**
* Check if index is set to be stored on disk
*
* @see NdbDictionary::Index::setLogging
*/
bool getLogging() const;
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
void setStoredIndex(bool x) { setLogging(x); }
bool getStoredIndex() const { return getLogging(); }
#endif
/**
* Get object status
*/
virtual Object::Status getObjectStatus() const;
/**
* Get object version
*/
virtual int getObjectVersion() const;
/** @} *******************************************************************/
private:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
@ -941,41 +1012,12 @@ public:
const struct NdbError & getNdbError() const;
/** @} *******************************************************************/
/**
* @name Tables
* @name Retrieving references to Tables and Indexes
* @{
*/
/**
* Create defined table given defined Table instance
* @param Table Table to create
* @return 0 if successful otherwise -1.
*/
int createTable(const Table &);
/**
* Drop table given retrieved Table instance
* @param Table Table to drop
* @return 0 if successful otherwise -1.
*/
int dropTable(Table &);
/**
* Drop table given table name
* @param name Name of table to drop
* @return 0 if successful otherwise -1.
*/
int dropTable(const char * name);
/**
* Alter defined table given defined Table instance
* @param Table Table to alter
* @return -2 (incompatible version) <br>
* -1 general error <br>
* 0 success
*/
int alterTable(const Table &);
/**
* Get table with given name, NULL if undefined
* @param name Name of table to get
@ -983,50 +1025,6 @@ public:
*/
const Table * getTable(const char * name);
/**
* Get table with given name for alteration.
* @param name Name of table to alter
* @return table if successful. NULL if undefined
*/
Table getTableForAlteration(const char * name);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Invalidate cached table object
* @param name Name of table to invalidate
*/
void invalidateTable(const char * name);
#endif
/**
* Remove table/index from local cache
*/
void removeCachedTable(const char * table);
void removeCachedIndex(const char * index, const char * table);
/** @} *******************************************************************/
/**
* @name Indexes
* @{
*/
/**
* Create index given defined Index instance
* @param Index to create
* @return 0 if successful otherwise -1.
*/
int createIndex(const Index &);
/**
* Drop index with given name
* @param indexName Name of index to drop.
* @param tableName Name of table that index belongs to.
* @return 0 if successful otherwise -1.
*/
int dropIndex(const char * indexName,
const char * tableName);
/**
* Get index with given name, NULL if undefined
* @param indexName Name of index to get.
@ -1036,14 +1034,6 @@ public:
const Index * getIndex(const char * indexName,
const char * tableName);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Invalidate cached index object
*/
void invalidateIndex(const char * indexName,
const char * tableName);
#endif
/**
* Fetch list of indexes of given table.
* @param list Reference to list where to store the listed indexes
@ -1081,6 +1071,102 @@ public:
/** @} *******************************************************************/
/**
* @name Table creation
* @{
*
* These methods should normally not be used in an application as
* the result will not be visible from the MySQL Server
*/
/**
* Create defined table given defined Table instance
* @param Table Table to create
* @return 0 if successful otherwise -1.
*/
int createTable(const Table &);
/**
* Drop table given retrieved Table instance
* @param Table Table to drop
* @return 0 if successful otherwise -1.
*/
int dropTable(Table &);
/**
* Drop table given table name
* @param name Name of table to drop
* @return 0 if successful otherwise -1.
*/
int dropTable(const char * name);
/**
* Alter defined table given defined Table instance
* @param Table Table to alter
* @return -2 (incompatible version) <br>
* -1 general error <br>
* 0 success
*/
int alterTable(const Table &);
/**
* Get table with given name for alteration.
* @param name Name of table to alter
* @return table if successful. NULL if undefined
*/
Table getTableForAlteration(const char * name);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Invalidate cached table object
* @param name Name of table to invalidate
*/
void invalidateTable(const char * name);
#endif
/**
* Remove table/index from local cache
*/
void removeCachedTable(const char * table);
void removeCachedIndex(const char * index, const char * table);
/** @} *******************************************************************/
/**
* @name Index creation
* @{
*
* These methods should normally not be used in an application as
* the result will not be visible from the MySQL Server
*
*/
/**
* Create index given defined Index instance
* @param Index to create
* @return 0 if successful otherwise -1.
*/
int createIndex(const Index &);
/**
* Drop index with given name
* @param indexName Name of index to drop.
* @param tableName Name of table that index belongs to.
* @return 0 if successful otherwise -1.
*/
int dropIndex(const char * indexName,
const char * tableName);
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/**
* Invalidate cached index object
*/
void invalidateIndex(const char * indexName,
const char * tableName);
#endif
/** @} *******************************************************************/
protected:
Dictionary(Ndb & ndb);
~Dictionary();