MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbDictionary.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NdbDictionary_H
19 #define NdbDictionary_H
20 
21 #include <ndb_types.h>
22 
23 class Ndb;
24 struct charset_info_st;
25 typedef struct charset_info_st CHARSET_INFO;
26 
27 /* Forward declaration only. */
28 class NdbRecord;
29 
67 public:
68  NdbDictionary() {} /* Remove gcc warning */
73  class Object {
74  public:
75  Object() {} /* Remove gcc warning */
76  virtual ~Object() {} /* Remove gcc warning */
80  enum Status {
81  New,
82 
84 
85 
87 
89 
91 
92  };
93 
97  virtual Status getObjectStatus() const = 0;
98 
102  virtual int getObjectVersion() const = 0;
103 
104  virtual int getObjectId() const = 0;
105 
109  enum Type {
112  UserTable = 2,
119  TableEvent = 11,
120  Tablespace = 20,
122  Datafile = 22,
123  Undofile = 23,
124  ReorgTrigger = 19,
125  HashMap = 24
126  };
127 
131  enum State {
139  };
140 
144  enum Store {
148  };
149 
161  enum FragmentType {
167  DistrKeyHash = 5,
168  DistrKeyLin = 6,
169  UserDefined = 7,
170  HashMapPartition = 9
171  };
172  private:
173  Object&operator=(const Object&);
174  };
175 
176  class Dictionary; // Forward declaration
177 
178  class ObjectId : public Object
179  {
180  public:
181  ObjectId();
182  virtual ~ObjectId();
183 
187  virtual Status getObjectStatus() const;
188 
192  virtual int getObjectVersion() const;
193 
194  virtual int getObjectId() const;
195 
196  private:
197  friend class NdbDictObjectImpl;
198  class NdbDictObjectImpl & m_impl;
199 
200  ObjectId(const ObjectId&); // Not impl.
201  ObjectId&operator=(const ObjectId&);
202  };
203 
204  class Table; // forward declaration
205  class Tablespace; // forward declaration
206  class HashMap; // Forward
207 // class NdbEventOperation; // forward declaration
208 
226  class Column {
227  public:
231  enum Type {
232  Undefined = NDB_TYPE_UNDEFINED,
233  Tinyint = NDB_TYPE_TINYINT,
234  Tinyunsigned = NDB_TYPE_TINYUNSIGNED,
235  Smallint = NDB_TYPE_SMALLINT,
236  Smallunsigned = NDB_TYPE_SMALLUNSIGNED,
237  Mediumint = NDB_TYPE_MEDIUMINT,
238  Mediumunsigned = NDB_TYPE_MEDIUMUNSIGNED,
239  Int = NDB_TYPE_INT,
240  Unsigned = NDB_TYPE_UNSIGNED,
241  Bigint = NDB_TYPE_BIGINT,
242  Bigunsigned = NDB_TYPE_BIGUNSIGNED,
243  Float = NDB_TYPE_FLOAT,
244  Double = NDB_TYPE_DOUBLE,
245  Olddecimal = NDB_TYPE_OLDDECIMAL,
246  Olddecimalunsigned = NDB_TYPE_OLDDECIMALUNSIGNED,
247  Decimal = NDB_TYPE_DECIMAL,
248  Decimalunsigned = NDB_TYPE_DECIMALUNSIGNED,
249  Char = NDB_TYPE_CHAR,
250  Varchar = NDB_TYPE_VARCHAR,
251  Binary = NDB_TYPE_BINARY,
252  Varbinary = NDB_TYPE_VARBINARY,
253  Datetime = NDB_TYPE_DATETIME,
254  Date = NDB_TYPE_DATE,
255  Blob = NDB_TYPE_BLOB,
256  Text = NDB_TYPE_TEXT,
257  Bit = NDB_TYPE_BIT,
258  Longvarchar = NDB_TYPE_LONGVARCHAR,
259  Longvarbinary = NDB_TYPE_LONGVARBINARY,
260  Time = NDB_TYPE_TIME,
261  Year = NDB_TYPE_YEAR,
262  Timestamp = NDB_TYPE_TIMESTAMP
263  };
264 
265  /*
266  * Array type specifies internal attribute format.
267  *
268  * - ArrayTypeFixed is stored as fixed number of bytes. This type
269  * is fastest to access but can waste space.
270  *
271  * - ArrayTypeVar is stored as variable number of bytes with a fixed
272  * overhead of 2 bytes.
273  *
274  * Default is ArrayTypeVar for Var* types and ArrayTypeFixed for
275  * others. The default is normally ok.
276  */
277  enum ArrayType {
278  ArrayTypeFixed = NDB_ARRAYTYPE_FIXED, // 0 length bytes
279  ArrayTypeShortVar = NDB_ARRAYTYPE_SHORT_VAR, // 1 length bytes
280  ArrayTypeMediumVar = NDB_ARRAYTYPE_MEDIUM_VAR // 2 length bytes
281  };
282 
283  /*
284  * Storage type specifies whether attribute is stored in memory or
285  * on disk. Default is memory. Disk attributes are potentially
286  * much slower to access and cannot be indexed in version 5.1.
287  */
288  enum StorageType {
289  StorageTypeMemory = NDB_STORAGETYPE_MEMORY,
290  StorageTypeDisk = NDB_STORAGETYPE_DISK,
291  StorageTypeDefault = NDB_STORAGETYPE_DEFAULT
292  };
293 
303  const char* getName() const;
304 
308  bool getNullable() const;
309 
313  bool getPrimaryKey() const;
314 
318  int getColumnNo() const;
319 
320 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
321  int getAttrId() const;
322 #endif
323 
329  bool equal(const Column& column) const;
330 
331 
341  Type getType() const;
342 
347  int getPrecision() const;
348 
353  int getScale() const;
354 
359  int getLength() const;
360 
366  CHARSET_INFO* getCharset() const;
367 
371  int getCharsetNumber() const;
372 
377  int getInlineSize() const;
378 
384  int getPartSize() const;
385 
390  int getStripeSize() const;
391 
395  int getSize() const;
396 
415  bool getPartitionKey() const;
416 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
417  inline bool getDistributionKey() const { return getPartitionKey(); };
418 #endif
419 
420  ArrayType getArrayType() const;
421  StorageType getStorageType() const;
422 
426  bool getDynamic() const;
427 
432  bool getIndexSourced() const;
433 
450  Column(const char * name = "");
455  Column(const Column& column);
456  ~Column();
457 
462  int setName(const char * name);
463 
467  void setNullable(bool);
468 
472  void setPrimaryKey(bool);
473 
482  void setType(Type type);
483 
488  void setPrecision(int);
489 
494  void setScale(int);
495 
500  void setLength(int length);
501 
507  void setCharset(CHARSET_INFO* cs);
508 
514  void setInlineSize(int size);
515 
521  void setPartSize(int size);
522 
543  void setStripeSize(int size);
544 
552  void setPartitionKey(bool enable);
553 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
554  inline void setDistributionKey(bool enable)
555  { setPartitionKey(enable); };
556 #endif
557 
558  void setArrayType(ArrayType type);
559  void setStorageType(StorageType type);
560 
564  void setDynamic(bool);
565 
568 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
569  int setDefaultValue(const char*);
570 #endif
571  /* setDefaultValue
572  * Set buf to NULL for no default value, or null default value for
573  * NULLABLE column, otherwise set buf to pointer to default value.
574  * The len parameter is the number of significant bytes of default
575  * value supplied, which is the type size for fixed size types.
576  * For variable length types, the leading 1 or 2 bytes pointed to
577  * by buf also contain length information as normal for the type.
578  */
579  int setDefaultValue(const void* buf, unsigned int len);
580 
581  /* getDefaultValue
582  * Get the default value data for this column.
583  * Optional int len* will be updated with the significant length
584  * of the default value, or set to 0 for NULL or no default.
585  */
586  const void* getDefaultValue(unsigned int* len = 0) const;
587 
588 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
589  const Table * getBlobTable() const;
590 
591  void setAutoIncrement(bool);
592  bool getAutoIncrement() const;
593  void setAutoIncrementInitialValue(Uint64 val);
594 
595  static const Column * FRAGMENT;
596  static const Column * FRAGMENT_FIXED_MEMORY;
597  static const Column * FRAGMENT_VARSIZED_MEMORY;
598  static const Column * ROW_COUNT;
599  static const Column * COMMIT_COUNT;
600  static const Column * ROW_SIZE;
601  static const Column * RANGE_NO;
602  static const Column * DISK_REF;
603  static const Column * RECORDS_IN_RANGE;
604  static const Column * ROWID;
605  static const Column * ROW_GCI;
606  static const Column * ROW_GCI64;
607  static const Column * ROW_AUTHOR;
608  static const Column * ANY_VALUE;
609  static const Column * COPY_ROWID;
610  static const Column * LOCK_REF;
611  static const Column * OP_ID;
612  static const Column * OPTIMIZE;
613  static const Column * FRAGMENT_EXTENT_SPACE;
614  static const Column * FRAGMENT_FREE_EXTENT_SPACE;
615 
616  int getSizeInBytes() const;
617 
618  int getBlobVersion() const; // NDB_BLOB_V1 or NDB_BLOB_V2
619  void setBlobVersion(int blobVersion); // default NDB_BLOB_V2
620 
625  int isBindable(const Column&) const;
626 #endif
627 
628  private:
629 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
630  friend class NdbRecAttr;
631  friend class NdbColumnImpl;
632 #endif
633  class NdbColumnImpl & m_impl;
635  Column& operator=(const Column&);
636  };
637 
638 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
639 
642  typedef Column Attribute;
643 #endif
644 
664  class Table : public Object {
665  public:
666  /*
667  * Single user mode specifies access rights to table during single user mode
668  */
669  enum SingleUserMode {
670  SingleUserModeLocked = NDB_SUM_LOCKED,
671  SingleUserModeReadOnly = NDB_SUM_READONLY,
672  SingleUserModeReadWrite = NDB_SUM_READ_WRITE
673  };
674 
683  const char * getName() const;
684 
688  int getTableId() const;
689 
694  const Column* getColumn(const char * name) const;
695 
700  Column* getColumn(const int attributeId);
701 
706  Column* getColumn(const char * name);
707 
712  const Column* getColumn(const int attributeId) const;
713 
731  bool getLogging() const;
732 
737 
743  int getKValue() const;
744 
752  int getMinLoadFactor() const;
753 
762  int getMaxLoadFactor() const;
763 
773  int getNoOfColumns() const;
774 
778  int getNoOfAutoIncrementColumns() const;
779 
783  int getNoOfPrimaryKeys() const;
784 
788  const char* getPrimaryKey(int no) const;
789 
793  bool equal(const Table&) const;
794 
798  const void* getFrmData() const;
799  Uint32 getFrmLength() const;
800 
806  const NdbRecord* getDefaultRecord() const;
807 
823  Table(const char * name = "");
824 
829  Table(const Table& table);
830  virtual ~Table();
831 
836  Table& operator=(const Table& table);
837 
842  int setName(const char * name);
843 
848  int addColumn(const Column &);
849 
853  void setLogging(bool);
854 
858  void setLinearFlag(Uint32 flag);
859  bool getLinearFlag() const;
860 
864  void setFragmentCount(Uint32);
865 
869  Uint32 getFragmentCount() const;
870 
875 
881  void setKValue(int kValue);
882 
890  void setMinLoadFactor(int);
891 
900  void setMaxLoadFactor(int);
901 
902  int setTablespaceName(const char * name);
903  const char * getTablespaceName() const;
904  int setTablespace(const class Tablespace &);
905  bool getTablespace(Uint32 *id= 0, Uint32 *version= 0) const;
906 
907  bool getHashMap(Uint32* id = 0, Uint32* version = 0) const;
908  int setHashMap(const class HashMap &);
909 
913  Object::Type getObjectType() const;
914 
918  virtual Object::Status getObjectStatus() const;
919  void setStatusInvalid() const;
920 
924  virtual int getObjectVersion() const;
925 
929  void setDefaultNoPartitionsFlag(Uint32 indicator);
930  Uint32 getDefaultNoPartitionsFlag() const;
931 
935  virtual int getObjectId() const;
936 
940  int setFrm(const void* data, Uint32 len);
941 
950  int setFragmentData(const Uint32 * nodegroups, Uint32 cnt);
951 
955  const Uint32 *getFragmentData() const;
956  Uint32 getFragmentDataLen() const;
957 
965  int setRangeListData(const Int32* data, Uint32 cnt);
966 
970  const Int32 *getRangeListData() const;
971  Uint32 getRangeListDataLen() const;
972 
980  Uint32 getFragmentNodes(Uint32 fragmentId,
981  Uint32* nodeIdArrayPtr,
982  Uint32 arraySize) const;
983 
988 
993  void setMaxRows(Uint64 maxRows);
994  Uint64 getMaxRows() const;
995 
1000  void setMinRows(Uint64 minRows);
1001  Uint64 getMinRows() const;
1002 
1006  void setSingleUserMode(enum SingleUserMode);
1007  enum SingleUserMode getSingleUserMode() const;
1008 
1009 
1015  void setRowGCIIndicator(bool value);
1016  bool getRowGCIIndicator() const;
1017 
1018  void setRowChecksumIndicator(bool value);
1019  bool getRowChecksumIndicator() const;
1020 
1021 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1022  const char *getMysqlName() const;
1023 
1024  void setStoredTable(bool x) { setLogging(x); }
1025  bool getStoredTable() const { return getLogging(); }
1026 
1027  int getRowSizeInBytes() const ;
1028  int createTableInDb(Ndb*, bool existingEqualIsOk = true) const ;
1029 
1030  int getReplicaCount() const ;
1031 
1032  bool getTemporary() const;
1033  void setTemporary(bool);
1034 
1040  bool getForceVarPart() const;
1041  void setForceVarPart(bool);
1042 
1051  int checkColumns(const Uint32* bitmap, unsigned len_in_bytes) const;
1052 
1059  void assignObjId(const ObjectId &);
1060 
1064  void setStorageType(Column::StorageType);
1065  Column::StorageType getStorageType() const;
1066 
1070  void setExtraRowGciBits(Uint32);
1071  Uint32 getExtraRowGciBits() const;
1072 
1076  void setExtraRowAuthorBits(Uint32);
1077  Uint32 getExtraRowAuthorBits() const;
1078 #endif
1079 
1080  // these 2 are not de-doxygenated
1081 
1095  int aggregate(struct NdbError& error);
1096 
1109  int validate(struct NdbError& error);
1110 
1116  Uint32 getPartitionId(Uint32 hashvalue) const ;
1117 
1118  /*
1119  * Return TRUE if any of the columns in the table have a
1120  * non NULL default value defined
1121  */
1122  bool hasDefaultValues() const;
1123 
1124  private:
1125 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1126  friend class Ndb;
1127  friend class NdbDictionaryImpl;
1128  friend class NdbTableImpl;
1129  friend class NdbEventOperationImpl;
1130 #endif
1131  class NdbTableImpl & m_impl;
1132  Table(NdbTableImpl&);
1133  };
1134 
1139  class Index : public Object {
1140  public:
1141 
1150  const char * getName() const;
1151 
1155  const char * getTable() const;
1156 
1160  unsigned getNoOfColumns() const;
1161 
1162 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1163 
1167  int getNoOfIndexColumns() const;
1168 #endif
1169 
1173  const Column * getColumn(unsigned no) const ;
1174 
1175 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1176 
1180  const char * getIndexColumn(int no) const ;
1181 #endif
1182 
1186  enum Type {
1189 
1191  };
1192 
1196  Type getType() const;
1197 
1206  bool getLogging() const;
1207 
1211  virtual Object::Status getObjectStatus() const;
1212 
1216  virtual int getObjectVersion() const;
1217 
1221  virtual int getObjectId() const;
1222 
1229  const NdbRecord* getDefaultRecord() const;
1230 
1246  Index(const char * name = "");
1247  virtual ~Index();
1248 
1252  int setName(const char * name);
1253 
1257  int setTable(const char * name);
1258 
1264  int addColumn(const Column & c);
1265 
1271  int addColumnName(const char * name);
1272 
1273 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1274 
1280  int addIndexColumn(const char * name);
1281 #endif
1282 
1288  int addColumnNames(unsigned noOfNames, const char ** names);
1289 
1290 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1291 
1297  int addIndexColumns(int noOfNames, const char ** names);
1298 #endif
1299 
1303  void setType(Type type);
1304 
1312  void setLogging(bool enable);
1313 
1314 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
1315  void setStoredIndex(bool x) { setLogging(x); }
1316  bool getStoredIndex() const { return getLogging(); }
1317 
1318  bool getTemporary() const;
1319  void setTemporary(bool);
1320 #endif
1321 
1324  private:
1325 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1326  friend class NdbIndexImpl;
1327  friend class NdbIndexStat;
1328 #endif
1329  class NdbIndexImpl & m_impl;
1330  Index(NdbIndexImpl&);
1331  };
1332 
1338  public:
1350  int next();
1356  int close();
1357  private:
1358 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1359  friend class NdbOptimizeTableHandleImpl;
1360  friend class NdbOptimizeIndexHandleImpl;
1361  friend class NdbDicitionaryImpl;
1362 #endif
1363  class NdbOptimizeTableHandleImpl & m_impl;
1365  };
1366 
1372  public:
1384  int next();
1390  int close();
1391  private:
1392 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1393  friend class NdbOptimizeIndexHandleImpl;
1394  friend class NdbDicitionaryImpl;
1395 #endif
1396  class NdbOptimizeIndexHandleImpl & m_impl;
1398  };
1399 
1404  class Event : public Object {
1405  public:
1409 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1410 
1411 #endif
1412  enum TableEvent {
1413  TE_INSERT =1<<0,
1414  TE_DELETE =1<<1,
1415  TE_UPDATE =1<<2,
1416 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1417  TE_SCAN =1<<3,
1418  TE_FIRST_NON_DATA_EVENT =1<<4,
1419 #endif
1420  TE_DROP =1<<4,
1421  TE_ALTER =1<<5,
1422  TE_CREATE =1<<6,
1425  TE_STOP =1<<9,
1427  TE_SUBSCRIBE =1<<11,
1429  TE_ALL=0xFFFF
1430 
1431  };
1432 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1433  enum _TableEvent {
1434  _TE_INSERT=0,
1435  _TE_DELETE=1,
1436  _TE_UPDATE=2,
1437  _TE_SCAN=3,
1438  _TE_FIRST_NON_DATA_EVENT=4,
1439  _TE_DROP=4,
1440  _TE_ALTER=5,
1441  _TE_CREATE=6,
1442  _TE_GCP_COMPLETE=7,
1443  _TE_CLUSTER_FAILURE=8,
1444  _TE_STOP=9,
1445  _TE_NODE_FAILURE=10,
1446  _TE_SUBSCRIBE=11,
1447  _TE_UNSUBSCRIBE=12,
1448  _TE_NUL=13, // internal (e.g. INS o DEL within same GCI)
1449  _TE_ACTIVE=14 // internal (node becomes active)
1450  };
1451 #endif
1452 
1457  ED_UNDEFINED
1458 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1459  = 0
1460 #endif
1461 #if 0 // not supported
1462  ,ED_SESSION = 1,
1463  // Only this API can use it
1464  // and it's deleted after api has disconnected or ndb has restarted
1465 
1466  ED_TEMPORARY = 2
1467  // All API's can use it,
1468  // But's its removed when ndb is restarted
1469 #endif
1471 
1472 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1473  = 3
1474 #endif
1475  };
1476 
1481  ER_UPDATED = 0,
1482  ER_ALL = 1, // except not-updated blob inlines
1483  ER_SUBSCRIBE = 2,
1484  ER_DDL = 4
1485  };
1486 
1491  Event(const char *name);
1497  Event(const char *name, const NdbDictionary::Table& table);
1498  virtual ~Event();
1502  int setName(const char *name);
1506  const char *getName() const;
1512  const NdbDictionary::Table * getTable() const;
1522  void setTable(const NdbDictionary::Table& table);
1529  int setTable(const char *tableName);
1535  const char* getTableName() const;
1539  void addTableEvent(const TableEvent te);
1543  bool getTableEvent(const TableEvent te) const;
1555  void setReport(EventReport);
1559  EventReport getReport() const;
1560 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1561  void addColumn(const Column &c);
1562 #endif
1563 
1570  void addEventColumn(unsigned attrId);
1578  void addEventColumn(const char * columnName);
1588  void addEventColumns(int n, const char ** columnNames);
1589 
1595  int getNoOfEventColumns() const;
1596 
1600  const Column * getEventColumn(unsigned no) const;
1601 
1618  void mergeEvents(bool flag);
1619 
1623  virtual Object::Status getObjectStatus() const;
1624 
1628  virtual int getObjectVersion() const;
1629 
1633  virtual int getObjectId() const;
1634 
1635 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1636  void print();
1637 #endif
1638 
1639  private:
1640 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
1641  friend class NdbEventImpl;
1642  friend class NdbEventOperationImpl;
1643 #endif
1644  class NdbEventImpl & m_impl;
1645  Event(NdbEventImpl&);
1646  };
1647 
1648  /* Flags for createRecord(). */
1649  enum NdbRecordFlags {
1650  /*
1651  Use special mysqld varchar format in index keys, used only from
1652  inside mysqld.
1653  */
1654  RecMysqldShrinkVarchar= 0x1,
1655  /* Use the mysqld record format for bitfields, only used inside mysqld. */
1656  RecMysqldBitfield= 0x2
1657  };
1659  /*
1660  Column described by this entry (the column maximum size defines field
1661  size in row).
1662  Note that even when creating an NdbRecord for an index, the column
1663  pointers must be to columns obtained from the underlying table, not
1664  from the index itself.
1665  Note that pseudo columns cannot be used as part of a RecordSpecification.
1666  To read pesudo column values, use the extra get value and set value
1667  APIs.
1668  */
1669  const Column *column;
1670  /*
1671  Offset of data from start of a row.
1672 
1673  For reading blobs, the blob handle (NdbBlob *) will be written into the
1674  result row when the operation is created, not the actual blob data.
1675  So at least sizeof(NdbBlob *) must be available in the row. Other
1676  operations do not write the blob handle into the row.
1677  In any case, a blob handle can always be obtained with a call to
1678  NdbOperation/NdbScanOperation::getBlobHandle().
1679  */
1680  Uint32 offset;
1681  /*
1682  Offset from start of row of byte containing NULL bit.
1683  Not used for columns that are not NULLable.
1684  */
1685  Uint32 nullbit_byte_offset;
1686  /* NULL bit, 0-7. Not used for columns that are not NULLable. */
1687  Uint32 nullbit_bit_in_byte;
1688  };
1689 
1690  /* Types of NdbRecord object */
1691  enum RecordType {
1692  TableAccess,
1693  IndexAccess
1694  };
1695 
1696  /*
1697  Return the type of the passed NdbRecord object
1698  */
1699  static RecordType getRecordType(const NdbRecord* record);
1700 
1701  /*
1702  Return the name of the table object that the NdbRecord
1703  refers to.
1704  This method returns Null if the NdbRecord object is not a
1705  TableAccess NdbRecord.
1706  */
1707  static const char* getRecordTableName(const NdbRecord* record);
1708 
1709  /*
1710  Return the name of the index object that the NdbRecord
1711  refers to.
1712  This method returns Null if the NdbRecord object is not an
1713  IndexAccess NdbRecord
1714  */
1715  static const char* getRecordIndexName(const NdbRecord* record);
1716 
1717  /*
1718  Get the first Attribute Id specified in the NdbRecord object.
1719  Returns false if no Attribute Ids are specified.
1720  */
1721  static bool getFirstAttrId(const NdbRecord* record, Uint32& firstAttrId);
1722 
1723  /* Get the next Attribute Id specified in the NdbRecord object
1724  after the attribute Id passed in.
1725  Returns false if there are no more attribute Ids
1726  */
1727  static bool getNextAttrId(const NdbRecord* record, Uint32& attrId);
1728 
1729  /* Get offset of the given attribute id's storage from the start
1730  of the NdbRecord row.
1731  Returns false if the attribute id is not present
1732  */
1733  static bool getOffset(const NdbRecord* record, Uint32 attrId, Uint32& offset);
1734 
1735  /* Get offset of the given attribute id's null bit from the start
1736  of the NdbRecord row.
1737  Returns false if the attribute is not present or if the
1738  attribute is not nullable
1739  */
1740  static bool getNullBitOffset(const NdbRecord* record,
1741  Uint32 attrId,
1742  Uint32& nullbit_byte_offset,
1743  Uint32& nullbit_bit_in_byte);
1744 
1745  /*
1746  Return pointer to beginning of storage of data specified by
1747  attrId.
1748  This method looks up the offset of the column which is stored in
1749  the NdbRecord object, and returns the value of row + offset.
1750  There are row-const and non-row-const versions.
1751 
1752  @param record : Pointer to NdbRecord object describing the row format
1753  @param row : Pointer to the start of row data
1754  @param attrId : Attribute id of column
1755  @return : Pointer to start of the attribute in the row. Null if the
1756  attribute is not part of the NdbRecord definition
1757  */
1758  static const char* getValuePtr(const NdbRecord* record,
1759  const char* row,
1760  Uint32 attrId);
1761 
1762  static char* getValuePtr(const NdbRecord* record,
1763  char* row,
1764  Uint32 attrId);
1765 
1766  /*
1767  Return a bool indicating whether the null bit for the given
1768  column is set to true or false.
1769  The location of the null bit in relation to the row pointer is
1770  obtained from the passed NdbRecord object.
1771  If the column is not nullable, false will be returned.
1772  If the column is not part of the NdbRecord definition, false will
1773  be returned.
1774 
1775  @param record : Pointer to NdbRecord object describing the row format
1776  @param row : Pointer to the start of row data
1777  @param attrId : Attibute id of column
1778  @return : true if attrId exists in NdbRecord, is nullable, and null bit
1779  in row is set, false otherwise.
1780  */
1781  static bool isNull(const NdbRecord* record,
1782  const char* row,
1783  Uint32 attrId);
1784 
1785  /*
1786  Set the null bit for the given column to the supplied value.
1787  The offset for the null bit is obtained from the passed
1788  NdbRecord object.
1789 
1790  If the attrId is not part of the NdbRecord, or is not nullable
1791  then an error will be returned.
1792 
1793  @param record : Pointer to NdbRecord object describing the row format
1794  @param row : Pointer to the start of row data
1795  @param atrId : Attribute id of the column
1796  @param value : Value to set null bit to
1797  @returns : 0 in success, -1 if the attrId is not part of the record,
1798  or is not nullable
1799  */
1800  static int setNull(const NdbRecord* record,
1801  char* row,
1802  Uint32 attrId,
1803  bool value);
1804 
1805  /*
1806  Return the number of bytes needed to store one row of data
1807  laid out as described by the passed NdbRecord structure.
1808  */
1809  static Uint32 getRecordRowLength(const NdbRecord* record);
1810 
1811  /*
1812  Return an empty column presence bitmask.
1813  This bitmask can be used with any NdbRecord to specify that
1814  no NdbRecord columns are to be included in the operation.
1815  */
1816  static const unsigned char* getEmptyBitmask();
1817 
1819  Uint32 min_free;
1820  Uint64 max_size;
1821  Uint64 file_size;
1822  const char * filename_pattern;
1823  };
1824 
1828  class LogfileGroup : public Object {
1829  public:
1830  LogfileGroup();
1831  LogfileGroup(const LogfileGroup&);
1832  virtual ~LogfileGroup();
1833 
1834  void setName(const char * name);
1835  const char* getName() const;
1836 
1837  void setUndoBufferSize(Uint32 sz);
1838  Uint32 getUndoBufferSize() const;
1839 
1840  void setAutoGrowSpecification(const AutoGrowSpecification&);
1841  const AutoGrowSpecification& getAutoGrowSpecification() const;
1842 
1843  Uint64 getUndoFreeWords() const;
1844 
1848  virtual Object::Status getObjectStatus() const;
1849 
1853  virtual int getObjectVersion() const;
1854 
1858  virtual int getObjectId() const;
1859 
1860  private:
1861  friend class NdbDictionaryImpl;
1862  friend class NdbLogfileGroupImpl;
1863  class NdbLogfileGroupImpl & m_impl;
1865  };
1866 
1870  class Tablespace : public Object {
1871  public:
1872  Tablespace();
1873  Tablespace(const Tablespace&);
1874  virtual ~Tablespace();
1875 
1876  void setName(const char * name);
1877  const char* getName() const;
1878 
1879  void setExtentSize(Uint32 sz);
1880  Uint32 getExtentSize() const;
1881 
1882  void setAutoGrowSpecification(const AutoGrowSpecification&);
1883  const AutoGrowSpecification& getAutoGrowSpecification() const;
1884 
1885  void setDefaultLogfileGroup(const char * name);
1886  void setDefaultLogfileGroup(const class LogfileGroup&);
1887 
1888  const char * getDefaultLogfileGroup() const;
1889  Uint32 getDefaultLogfileGroupId() const;
1890 
1894  virtual Object::Status getObjectStatus() const;
1895 
1899  virtual int getObjectVersion() const;
1900 
1904  virtual int getObjectId() const;
1905 
1906  private:
1907  friend class NdbTablespaceImpl;
1908  class NdbTablespaceImpl & m_impl;
1910  };
1911 
1912  class Datafile : public Object {
1913  public:
1914  Datafile();
1915  Datafile(const Datafile&);
1916  virtual ~Datafile();
1917 
1918  void setPath(const char * name);
1919  const char* getPath() const;
1920 
1921  void setSize(Uint64);
1922  Uint64 getSize() const;
1923  Uint64 getFree() const;
1924 
1925  int setTablespace(const char * name);
1926  int setTablespace(const class Tablespace &);
1927  const char * getTablespace() const;
1928  void getTablespaceId(ObjectId * dst) const;
1929 
1930  void setNode(Uint32 nodeId);
1931  Uint32 getNode() const;
1932 
1933  Uint32 getFileNo() const;
1934 
1938  virtual Object::Status getObjectStatus() const;
1939 
1943  virtual int getObjectVersion() const;
1944 
1948  virtual int getObjectId() const;
1949 
1950  private:
1951  friend class NdbDatafileImpl;
1952  class NdbDatafileImpl & m_impl;
1954  };
1955 
1956  class Undofile : public Object {
1957  public:
1958  Undofile();
1959  Undofile(const Undofile&);
1960  virtual ~Undofile();
1961 
1962  void setPath(const char * path);
1963  const char* getPath() const;
1964 
1965  void setSize(Uint64);
1966  Uint64 getSize() const;
1967 
1968  void setLogfileGroup(const char * name);
1969  void setLogfileGroup(const class LogfileGroup &);
1970  const char * getLogfileGroup() const;
1971  void getLogfileGroupId(ObjectId * dst) const;
1972 
1973  void setNode(Uint32 nodeId);
1974  Uint32 getNode() const;
1975 
1976  Uint32 getFileNo() const;
1977 
1981  virtual Object::Status getObjectStatus() const;
1982 
1986  virtual int getObjectVersion() const;
1987 
1991  virtual int getObjectId() const;
1992 
1993  private:
1994  friend class NdbUndofileImpl;
1995  class NdbUndofileImpl & m_impl;
1997  };
1998 
2004  class HashMap : public Object {
2005  public:
2006  HashMap();
2007  HashMap(const HashMap&);
2008  virtual ~HashMap();
2009 
2010  void setName(const char *);
2011  const char * getName() const;
2012 
2013  void setMap(const Uint32* values, Uint32 len);
2014  Uint32 getMapLen() const;
2015  int getMapValues(Uint32* dst, Uint32 len) const;
2016 
2021  bool equal(const HashMap&) const;
2022 
2026  virtual Object::Status getObjectStatus() const;
2027 
2031  virtual int getObjectVersion() const;
2032 
2036  virtual int getObjectId() const;
2037 
2038  private:
2039  friend class NdbHashMapImpl;
2040  class NdbHashMapImpl & m_impl;
2042  };
2043 
2048  class Dictionary {
2049  public:
2054  struct List {
2059  struct Element {
2060  unsigned id;
2064  Uint32 temp;
2065  char * database;
2066  char * schema;
2067  char * name;
2068  Element() :
2069  id(0),
2070  type(Object::TypeUndefined),
2071  state(Object::StateUndefined),
2072  store(Object::StoreUndefined),
2073  temp(NDB_TEMP_TAB_PERMANENT),
2074  database(0),
2075  schema(0),
2076  name(0) {
2077  }
2078  };
2079  unsigned count;
2081  List() : count(0), elements(0) {}
2082  ~List() {
2083  if (elements != 0) {
2084  for (unsigned i = 0; i < count; i++) {
2085  delete[] elements[i].database;
2086  delete[] elements[i].schema;
2087  delete[] elements[i].name;
2088  elements[i].name = 0;
2089  }
2090  delete[] elements;
2091  count = 0;
2092  elements = 0;
2093  }
2094  }
2095  };
2096 
2112 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
2114 #endif
2115  int listObjects(List & list,
2117  int listObjects(List & list,
2119  bool fullyQualified) const;
2120 
2126  const struct NdbError & getNdbError() const;
2127 
2133  int getWarningFlags() const;
2134 
2147  const Table * getTable(const char * name) const;
2148 
2149 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2150 
2153  const Table * getBlobTable(const Table *, const char * col_name);
2154  const Table * getBlobTable(const Table *, Uint32 col_no);
2155 
2156  /*
2157  * Save a table definition in dictionary cache
2158  * @param table Object to put into cache
2159  */
2160  void putTable(const Table * table);
2161 #endif
2162 
2169  const Index * getIndex(const char * indexName,
2170  const char * tableName) const;
2171 
2178 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
2179  int listIndexes(List & list, const char * tableName);
2180 #endif
2181  int listIndexes(List & list, const char * tableName) const;
2182 
2183 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2184 
2190  int listIndexes(List & list, const Table &table) const;
2191 #endif
2192 
2204  int createEvent(const Event &event);
2205 
2211  int dropEvent(const char * eventName, int force= 0);
2212 
2218  const Event * getEvent(const char * eventName);
2219 
2225 #ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
2226  int listEvents(List & list);
2227 #endif
2228  int listEvents(List & list) const;
2229 
2245  int createTable(const Table &table);
2246 
2253  int createTable(const Table &table, ObjectId * objid);
2254 
2261  int
2262  optimizeTable(const Table &t, OptimizeTableHandle &h);
2263 
2270  int
2271  optimizeIndex(const Index &ind, OptimizeIndexHandle &h);
2272 
2278  int dropTable(Table & table);
2279 
2285  int dropTable(const char * name);
2286 
2295  bool supportedAlterTable(const Table & f, const Table & t);
2296 
2297 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2298 
2306  int alterTable(const Table & f, const Table & t);
2307 
2312  void invalidateTable(const char * name);
2313 #endif
2314 
2318  void removeCachedTable(const char * table);
2322  void removeCachedIndex(const char * index, const char * table);
2323 
2324 
2340  int createIndex(const Index &index, bool offline = false);
2341  int createIndex(const Index &index, const Table &table, bool offline = false);
2342 
2349  int dropIndex(const char * indexName,
2350  const char * tableName);
2351 
2352  /*
2353  * Force update of ordered index stats. Scans an assigned fragment
2354  * in the kernel and updates result in stats tables. This one-time
2355  * update is independent of IndexStatAuto settings. Common use case
2356  * is mysql "analyze table".
2357  */
2358  int updateIndexStat(const Index&, const Table&);
2359 
2360  /*
2361  * Force update of ordered index stats where index is given by id.
2362  */
2363  int updateIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId);
2364 
2365  /*
2366  * Delete ordered index stats. If IndexStatAutoUpdate is set, also
2367  * stops automatic updates, until another forced update is done.
2368  */
2369  int deleteIndexStat(const Index&, const Table&);
2370 
2371  /*
2372  * Delete ordered index stats where index is given by id.
2373  */
2374  int deleteIndexStat(Uint32 indexId, Uint32 indexVersion, Uint32 tableId);
2375 
2376 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2377  void removeCachedTable(const Table *table);
2378  void removeCachedIndex(const Index *index);
2379  void invalidateTable(const Table *table);
2383  void invalidateIndex(const char * indexName,
2384  const char * tableName);
2385  void invalidateIndex(const Index *index);
2389  int forceGCPWait();
2390  int forceGCPWait(int type);
2391 
2395  int getRestartGCI(Uint32 * gci);
2396 #endif
2397 
2406  /*
2407  * The four "create" operations can return warning flags defined
2408  * below. See getWarningFlags().
2409  */
2410  enum {
2411  WarnUndobufferRoundUp = 0x1, // rounded up to kernel page size
2412  WarnUndofileRoundDown = 0x2, // rounded down to kernel page size
2413  WarnExtentRoundUp = 0x4, // rounded up to kernel page size
2414  WarnDatafileRoundDown = 0x8, // rounded down to kernel page size
2415  WarnDatafileRoundUp = 0x10 // rounded up to extent size
2416  };
2417 
2418  int createLogfileGroup(const LogfileGroup &, ObjectId* = 0);
2419  int dropLogfileGroup(const LogfileGroup&);
2420  LogfileGroup getLogfileGroup(const char * name);
2421 
2422  int createTablespace(const Tablespace &, ObjectId* = 0);
2423  int dropTablespace(const Tablespace&);
2424  Tablespace getTablespace(const char * name);
2425  Tablespace getTablespace(Uint32 tablespaceId);
2426 
2427  int createDatafile(const Datafile &, bool overwrite_existing = false, ObjectId* = 0);
2428  int dropDatafile(const Datafile&);
2429  Datafile getDatafile(Uint32 node, const char * path);
2430 
2431  int createUndofile(const Undofile &, bool overwrite_existing = false, ObjectId * = 0);
2432  int dropUndofile(const Undofile&);
2433  Undofile getUndofile(Uint32 node, const char * path);
2434 
2435 
2445  int createHashMap(const HashMap&, ObjectId* = 0);
2446 
2450  int getHashMap(HashMap& dst, const char* name);
2451 
2455  int getHashMap(HashMap& dst, const Table* table);
2456 
2460  int getDefaultHashMap(HashMap& dst, Uint32 fragments);
2461 
2462 
2466  int initDefaultHashMap(HashMap& dst, Uint32 fragments);
2467 
2472  int prepareHashMap(const Table& oldTable, Table& newTable);
2473 
2518  int beginSchemaTrans();
2519 
2535  int endSchemaTrans(Uint32 flags = 0);
2536 
2541  // abort transaction
2542  SchemaTransAbort = 1,
2543  // do not wait for reply, status is reported in cluster log
2544  SchemaTransBackground = 2
2545  };
2546 
2550  bool hasSchemaTrans() const;
2552 
2553  protected:
2554  Dictionary(Ndb & ndb);
2555  ~Dictionary();
2556 
2557  private:
2558 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2559  friend class NdbDictionaryImpl;
2560  friend class UtilTransactions;
2561  friend class NdbBlob;
2562 #endif
2563  class NdbDictionaryImpl & m_impl;
2565  const Table * getIndexTable(const char * indexName,
2566  const char * tableName) const;
2567  public:
2568 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
2569  const Table * getTable(const char * name, void **data) const;
2570  void set_local_table_data_size(unsigned sz);
2571 
2572  const Index * getIndexGlobal(const char * indexName,
2573  const Table &ndbtab) const;
2574  const Index * getIndexGlobal(const char * indexName,
2575  const char * tableName) const;
2576  const Table * getTableGlobal(const char * tableName) const;
2577  int alterTableGlobal(const Table &f, const Table &t);
2578  int dropTableGlobal(const Table &ndbtab);
2579  int dropIndexGlobal(const Index &index);
2580  int removeIndexGlobal(const Index &ndbidx, int invalidate) const;
2581  int removeTableGlobal(const Table &ndbtab, int invalidate) const;
2582  void invalidateDbGlobal(const char * dbname);
2583 #endif
2584 
2585  /*
2586  Create an NdbRecord for use in table operations.
2587  */
2589  const RecordSpecification *recSpec,
2590  Uint32 length,
2591  Uint32 elemSize,
2592  Uint32 flags= 0);
2593 
2594  /*
2595  Create an NdbRecord for use in index operations.
2596  */
2598  const Table *table,
2599  const RecordSpecification *recSpec,
2600  Uint32 length,
2601  Uint32 elemSize,
2602  Uint32 flags= 0);
2603  /*
2604  Create an NdbRecord for use in index operations.
2605  This variant assumes that the index is for a table in
2606  the current database and schema
2607  */
2609  const RecordSpecification *recSpec,
2610  Uint32 length,
2611  Uint32 elemSize,
2612  Uint32 flags= 0);
2613 
2614  /*
2615  Free an NdbRecord object created earlier with
2616  createRecord
2617  */
2618  void releaseRecord(NdbRecord *rec);
2619  }; // class Dictionary
2620 
2622  {
2623  public:
2625  virtual ~NdbDataPrintFormat();
2626  const char *lines_terminated_by;
2627  const char *fields_terminated_by;
2628  const char *start_array_enclosure;
2629  const char *end_array_enclosure;
2630  const char *fields_enclosed_by;
2631  const char *fields_optionally_enclosed_by;
2632  const char *hex_prefix;
2633  const char *null_string;
2634  int hex_format;
2635  };
2636 
2637  static
2638  class NdbOut& printFormattedValue(class NdbOut& out,
2639  const NdbDataPrintFormat& format,
2640  const NdbDictionary::Column* c,
2641  const void* val);
2642 
2643 
2644 }; // class NdbDictionary
2645 
2646 class NdbOut& operator <<(class NdbOut& out, const NdbDictionary::Column& col);
2647 
2648 #endif