In MySQL Cluster NDB 7.5.2 and later, the table comment in a
CREATE TABLE or ALTER
TABLE statement can also be used to specify an
NDB_TABLE option, which consists of one or
more name-value pairs, separated by commas if need be, following
the string NDB_TABLE=. Complete syntax for
names and values syntax is shown here:
COMMENT="NDB_TABLE=ndb_table_option[,ndb_table_option[,...]]"ndb_table_option: NOLOGGING={1|0} | READ_BACKUP={1|0} | FRAGMENT_COUNT_TYPE={ONE_PER_NODE|ONE_PER_NODE_GROUP|ONE_PER_LDM|ONE_PER_LDM_PER_NODE} | FULLY_REPLICATED={1|0}
Spaces are not permitted within the quoted string. The string is case-insensitive.
The four NDB table options that can be set as
part of a comment in this way are described in more detail in
the next few paragraphs.
NOLOGGING: Using 1 corresponds to having
ndb_table_no_logging enabled,
but has no actual effect. Provided as a placeholder, mostly for
completeness of ALTER TABLE
statements.
READ_BACKUP: Setting this option to 1 has the
same effect as though
ndb_read_backup were enabled;
enables reading from any replica. Setting this option to 1
automatically sets FRAGMENT_COUNT_TYPE to
ONE_PER_LDM_PER_NODE_GROUP (see next item).
Starting with MySQL Cluster NDB 7.5.3, you can set
READ_BACKUP for an existing table online,
using an ALTER TABLE statement similar to one
of those shown here:
ALTER TABLE ... ALGORITHM=INPLACE, COMMENT="NDB_TABLE=READ_BACKUP=1"; ALTER TABLE ... ALGORITHM=INPLACE, COMMENT="NDB_TABLE=READ_BACKUP=0";
(See Bug #80858, Bug #23001617). For more information about the
ALGORITHM option for ALTER
TABLE, see
Section 14.1.8.2, “ALTER TABLE Online Operations in MySQL Cluster”.
FRAGMENT_COUNT_TYPE: Provides additional
control over assignment and placement of partitions. The
following four schemes are supported:
ONE_PER_NODE: One partition per node.Only one LDM on each node stores a primary partition. Each partition is stored in the same LDM (same ID) on all nodes.
ONE_PER_NODE_GROUP: One partition per node group.Each node stores a single partition, which can be either a primary replica or a backup replica. Each partition is stored in the same LDM on all nodes.
ONE_PER_LDM_PER_NODE: One partition for each LDM on each node; the default.This is the same behavior as prior to MySQL Cluster NDB 7.5.2, except for a slightly different mapping of partitions to LDMs, starting with LDM 0 and placing one partition per node group, then moving on to the next LDM.
ONE_PER_LDM_PER_NODE_GROUP: One partition per LDM in each node group.These partitions can be primary or backup partitions.
This is the setting used if
READ_BACKUPis set to 1.
FULLY_REPLICATED controls whether the table
is fully replicated, that is, whether each data node has a
complete copy of the table. To enable full replication of the
table, use FULLY_REPLICATED=1. You must also
set (or have already set) the table's
FRAGMENT_COUNT_TYPE to either one of
ONE_PER_NODE_GROUP or
ONE_PER_LDM_PRE_NODE_GROUP in order for this
to work.
This setting can also be controlled using the
ndb_fully_replicated system variable. Setting
it to ON enables the option by default for
all new NDB tables; the default is
OFF, which maintains the previous behavior
(as in MySQL Cluster NDB 7.5.1 and earlier, before support for
fully replicated tables was introduced). The
ndb_data_node_neighbour system
variable is also used for fully replicated tables, to ensure
that when a fully replicated table is accessed, we access the
data node which is local to this MySQL Server.
An example of a CREATE TABLE statement using
such a comment when creating an NDB table is
shown here:
mysql>CREATE TABLE t1 (>c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,>c2 VARCHAR(100),>c3 VARCHAR(100) )>ENGINE=NDB>COMMENT="NDB_TABLE=READ_BACKUP=0,FRAGMENT_COUNT_TYPE=ONE_PER_NODE";
The comment is displayed as part of the ouput of
SHOW CREATE TABLE. The text of
the comment is also available from querying the MySQL
Information Schema TABLES table, as
in this example:
mysql>SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT>FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1";+------------+--------------+----------------------------------------------------------+ | TABLE_NAME | TABLE_SCHEMA | TABLE_COMMENT | +------------+--------------+----------------------------------------------------------+ | t1 | c | NDB_TABLE=READ_BACKUP=0,FRAGMENT_COUNT_TYPE=ONE_PER_NODE | | t1 | d | | +------------+--------------+----------------------------------------------------------+ 2 rows in set (0.00 sec)
This comment syntax is also supported with
ALTER TABLE statements for
NDB tables. Keep in mind that a table comment
used with ALTER TABLE replaces any existing
comment which the table might have.
mysql>ALTER TABLE t1 COMMENT="NDB_TABLE=FRAGMENT_COUNT_TYPE=ONE_PER_NODE_GROUP";Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql>SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT>FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1";+------------+--------------+--------------------------------------------------+ | TABLE_NAME | TABLE_SCHEMA | TABLE_COMMENT | +------------+--------------+--------------------------------------------------+ | t1 | c | NDB_TABLE=FRAGMENT_COUNT_TYPE=ONE_PER_NODE_GROUP | | t1 | d | | +------------+--------------+--------------------------------------------------+ 2 rows in set (0.01 sec)
Because the READ_BACKUP value was not carried
over to the new comment set by the ALTER
TABLE statement, there is no longer a way to retrieve
the value previously set for it. To avoid this from problem, it
is suggested that you preserve any such values from the existing
comment string, like this:
mysql>SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT>FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1";+------------+--------------+----------------------------------------------------------+ | TABLE_NAME | TABLE_SCHEMA | TABLE_COMMENT | +------------+--------------+----------------------------------------------------------+ | t1 | c | NDB_TABLE=READ_BACKUP=0,FRAGMENT_COUNT_TYPE=ONE_PER_NODE | | t1 | d | | +------------+--------------+----------------------------------------------------------+ 2 rows in set (0.00 sec) mysql>ALTER TABLE t1 COMMENT="NDB_TABLE=READ_BACKUP=0,FRAGMENT_COUNT_TYPE=ONE_PER_NODE_GROUP";Query OK, 0 rows affected (1.56 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql>SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT>FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1";+------------+--------------+----------------------------------------------------------------+ | TABLE_NAME | TABLE_SCHEMA | TABLE_COMMENT | +------------+--------------+----------------------------------------------------------------+ | t1 | c | NDB_TABLE=READ_BACKUP=0,FRAGMENT_COUNT_TYPE=ONE_PER_NODE_GROUP | | t1 | d | | +------------+--------------+----------------------------------------------------------------+ 2 rows in set (0.01 sec)