13.1.20.11 Setting NDB_TABLE Options设置NDB_TABLE选项

In MySQL NDB Cluster, 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=. 在MySQL NDB集群中,CREATE TABLEALTER TABLE语句中的表注释也可用于指定NDB_TABLE选项,该选项由一个或多个名称-值对组成,如果需要,在字符串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}
  | PARTITION_BALANCE={FOR_RP_BY_NODE | FOR_RA_BY_NODE | FOR_RP_BY_LDM
                      | FOR_RA_BY_LDM | FOR_RA_BY_LDM_X_2
                      | FOR_RA_BY_LDM_X_3 | FOR_RA_BY_LDM_X_4}
  | 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.以下几段将更详细地描述四个NDB表格选项,它们可以以这种方式设置为注释的一部分。

NOLOGGING: Using 1 corresponds to having ndb_table_no_logging enabled, but has no actual effect. :使用1对应于启用ndb_table_no_logging,但没有实际效果。Provided as a placeholder, mostly for completeness of ALTER TABLE statements.作为一个占位符提供,主要用于ALTER TABLE语句的完整性。

READ_BACKUP: Setting this option to 1 has the same effect as though ndb_read_backup were enabled; enables reading from any replica. Doing so greatly improves the performance of reads from the table at a relatively small cost to write performance. :将此选项设置为1具有与启用ndb_read_backup相同的效果;允许从任何复制副本进行读取。这样做可以大大提高从表中读取的性能,而写入性能的成本相对较低。Beginning with NDB 8.0.19, 1 is the default for READ_BACKUP, and the default for ndb_read_backup is ON (previously, read from any replica was disabled by default).从NDB 8.0.19开始,READ_BACKUP的默认值为1,ndb_read_backup的默认值为ON(以前,默认情况下禁用了从任何副本读取)。

You can set READ_BACKUP for an existing table online, using an ALTER TABLE statement similar to one of those shown here:您可以使用类似于下列语句之一的ALTER TABLE语句在线设置现有表的READ_BACKUP

ALTER TABLE ... ALGORITHM=INPLACE, COMMENT="NDB_TABLE=READ_BACKUP=1";

ALTER TABLE ... ALGORITHM=INPLACE, COMMENT="NDB_TABLE=READ_BACKUP=0";

For more information about the ALGORITHM option for ALTER TABLE, see Section 23.5.11, “Online Operations with ALTER TABLE in NDB Cluster”.有关ALTER TABLEALGORITHM选项的更多信息,请参阅第23.5.11节,“NDB集群中ALTER TABLE的在线操作”

PARTITION_BALANCE: Provides additional control over assignment and placement of partitions. :提供对分区的分配和放置的附加控制。The following four schemes are supported:支持以下四项计划:

  1. FOR_RP_BY_NODE: One partition per node.:每个节点一个分区。

    Only one LDM on each node stores a primary partition. 每个节点上只有一个LDM存储主分区。Each partition is stored in the same LDM (same ID) on all nodes.每个分区存储在所有节点上的相同LDM(相同ID)中。

  2. FOR_RA_BY_NODE: 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.每个分区存储在所有节点上的相同LDM中。

  3. FOR_RP_BY_LDM: One partition for each LDM on each node; the default.:每个节点上的每个LDM有一个分区;默认值。

    This is the setting used if READ_BACKUP is set to 1.这是在READ_BACKUP设置为1时使用的设置。

  4. FOR_RA_BY_LDM: One partition per LDM in each node group.:每个节点组中每个LDM一个分区。

    These partitions can be primary or backup partitions.这些分区可以是主分区或备份分区。

  5. FOR_RA_BY_LDM_X_2: Two partitions per LDM in each node group.:每个节点组中每个LDM有两个分区。

    These partitions can be primary or backup partitions.这些分区可以是主分区或备份分区。

  6. FOR_RA_BY_LDM_X_3: Three partitions per LDM in each node group.:每个节点组中每个LDM有三个分区。

    These partitions can be primary or backup partitions.这些分区可以是主分区或备份分区。

  7. FOR_RA_BY_LDM_X_4: Four partitions per LDM in each node group.:每个节点组中每个LDM有四个分区。

    These partitions can be primary or backup partitions.这些分区可以是主分区或备份分区。

PARTITION_BALANCE is the preferred interface for setting the number of partitions per table. PARTITION_BALANCE是设置每个表的分区数的首选接口。Using MAX_ROWS to force the number of partitions is deprecated but continues to be supported for backward compatibility; it is subject to removal in a future release of MySQL NDB Cluster. 不推荐使用MAX_ROWS强制分区数量,但仍然支持向后兼容;它将在MySQL NDB Cluster的未来版本中删除。(Bug #81759, Bug #23544301)

FULLY_REPLICATED controls whether the table is fully replicated, that is, whether each data node has a complete copy of the table. FULLY_REPLICATED控制表是否完全复制,即每个数据节点是否具有表的完整副本。To enable full replication of the table, use FULLY_REPLICATED=1.要启用表的完全复制,请使用FULLY_REPLICATED=1

This setting can also be controlled using the ndb_fully_replicated system variable. 也可以使用系统变量ndb_fully_replicated控制此设置。Setting it to ON enables the option by default for all new NDB tables; the default is OFF. 将其设置为ON将默认启用所有新NDB表的选项;默认设置为OFFThe 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.ndb_data_node_neighbour系统变量也用于完全复制的表,以确保在访问完全复制的表时,我们访问此MySQL服务器本地的数据节点。

An example of a CREATE TABLE statement using such a comment when creating an NDB table is shown here:创建NDB表时使用此类注释的CREATE TABLE语句示例如下所示:

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,PARTITION_BALANCE=FOR_RP_BY_NODE";

The comment is displayed as part of the ouput of SHOW CREATE TABLE. 注释显示为SHOW CREATE TABLE输出的一部分。The text of the comment is also available from querying the MySQL Information Schema TABLES table, as in this example:注释文本也可以通过查询MySQL信息架构TABLES表获得,如本例所示:

mysql> SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT
     > FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1"\G
*************************** 1. row ***************************
   TABLE_NAME: t1
 TABLE_SCHEMA: test
TABLE_COMMENT: NDB_TABLE=READ_BACKUP=0,PARTITION_BALANCE=FOR_RP_BY_NODE
1 row in set (0.01 sec)

This comment syntax is also supported with ALTER TABLE statements for NDB tables, as shown here:NDB表的ALTER TABLE语句也支持此注释语法,如下所示:

mysql> ALTER TABLE t1 COMMENT="NDB_TABLE=PARTITION_BALANCE=FOR_RA_BY_NODE";
Query OK, 0 rows affected (0.40 sec)
Records: 0  Duplicates: 0  Warnings: 0

Beginning with NDB 8.0.21, the TABLE_COMMENT column displays the comment that is required to re-create the table as it is following the ALTER TABLE statement, like this:从NDB 8.0.21开始,TABLE_COMMENT列显示重新创建表格所需的注释,因为它遵循ALTER TABLE语句,如下所示:

mysql> SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_COMMENT
    ->     FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME="t1"\G
*************************** 1. row ***************************
   TABLE_NAME: t1
 TABLE_SCHEMA: test
TABLE_COMMENT: NDB_TABLE=READ_BACKUP=0,PARTITION_BALANCE=FOR_RP_BY_NODE
1 row in set (0.01 sec)
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=PARTITION_BALANCE=FOR_RA_BY_NODE       |
| t1         | d            |                                                  |
+------------+--------------+--------------------------------------------------+
2 rows in set (0.01 sec)

Keep in mind that a table comment used with ALTER TABLE replaces any existing comment which the table might have.请记住,与ALTER TABLE一起使用的表注释将替换该表可能具有的任何现有注释。

mysql> ALTER TABLE t1 COMMENT="NDB_TABLE=PARTITION_BALANCE=FOR_RA_BY_NODE";
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=PARTITION_BALANCE=FOR_RA_BY_NODE       |
| t1         | d            |                                                  |
+------------+--------------+--------------------------------------------------+
2 rows in set (0.01 sec)

Prior to NDB 8.0.21, the table comment used with ALTER TABLE replaced any existing comment which the table might have had. 在NDB 8.0.21之前,与ALTER TABLE一起使用的表注释替换了该表可能具有的任何现有注释。This meant that (for example) the READ_BACKUP value was not carried over to the new comment set by the ALTER TABLE statement, and that any unspecified values reverted to their defaults. 这意味着(例如)READ_BACKUP值没有被ALTER TABLE语句带入新的注释集,任何未指定的值都会恢复为默认值。(BUG#30428829) There was thus no longer any way using SQL to retrieve the value previously set for the comment. 因此,不再使用SQL检索以前为注释设置的值。To keep comment values from reverting to their defaults, it was necessry to preserve any such values from the existing comment string and include them in the comment passed to ALTER TABLE.为了防止注释值恢复为默认值,有必要从现有注释字符串中保留任何此类值,并将它们包含在传递给ALTER TABLE的注释中。

You can also see the value of the PARTITION_BALANCE option in the output of ndb_desc. 您还可以在ndb_desc的输出中看到PARTITION_BALANCE选项的值。ndb_desc also shows whether the READ_BACKUP and FULLY_REPLICATED options are set for the table. ndb_desc还显示是否为表设置了READ_BACKUPFULLY_REPLICATED选项。See the description of this program for more information.有关更多信息,请参阅此程序的说明。