Purpose
This statement is used to create a new table in the database.
Syntax
CREATE [hint_options] TABLE [IF NOT EXISTS] table_name
(table_definition_list) [table_option_list] [partition_option] [IGNORE | REPLACE] [AS] select;
CREATE TABLE [IF NOT EXISTS] table_name
LIKE table_name;
table_definition_list:
table_definition [, table_definition ...]
table_definition:
column_definition
| [CONSTRAINT [constraint_name]] PRIMARY KEY index_desc
| [CONSTRAINT [constraint_name]] UNIQUE {INDEX | KEY} [index_name] index_desc
| [CONSTRAINT [constraint_name]] FOREIGN KEY [index_name] (column_name, ...) reference_definition
| {INDEX | KEY} [index_name] [index_type] (key_part,...) [index_optionn_list]
| [CONSTRAINT [constraint_name]] CHECK(expression) [NOT ENFORCED | ENFORCED]
column_definition_list:
column_definition [, column_definition ...]
column_definition:
column_name data_type
[DEFAULT const_value] [AUTO_INCREMENT]
[NULL | NOT NULL] [[PRIMARY] KEY] [UNIQUE [KEY]] comment
[COLUMN_FORMAT {FIXED | DYNAMIC | DEFAULT}]
[STORAGE {DISK | MEMORY}]
[reference_definition]
| column_name data_type
[GENERATED ALWAYS] AS (expr) [VIRTUAL | STORED]
[opt_generated_column_attribute]
[reference_definition]
index_desc:
(column_desc_list) [index_type] [index_option_list]
reference_definition:
REFERENCES tbl_name (key_part,...)
[match_action] [opt_reference_option_list]
match_action:
MATCH {SIMPLE | FULL | PARTIAL}
opt_reference_option_list:
reference_option [,reference_option ...]
reference_option:
ON {DELETE | UPDATE} {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}
key_part:
{index_col_name [(length)] | (expr)} [ASC | DESC]
index_type:
USING BTREE
index_option_list:
index_option [ index_option ...]
index_option:
[GLOBAL | LOCAL]
| block_size
| compression
| STORING(column_name_list)
| comment
| KEY_BLOCK_SIZE [=] INT_VALUE
| WITH PARSER parser_name
table_option_list:
table_option [ table_option ...]
table_option:
[DEFAULT] {CHARSET | CHARACTER SET} [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
| table_tablegroup
| block_size
| lob_inrow_threshold [=] num
| compression
| AUTO_INCREMENT [=] INT_VALUE
| comment
| TTL (ttl_definition)
| ROW_FORMAT [=] REDUNDANT|COMPACT|DYNAMIC|COMPRESSED|DEFAULT
| PCTFREE [=] num
| parallel_clause
| READ {ONLY | WRITE}
| DUPLICATE_SCOPE [=] 'none|cluster'
| KEY_BLOCK_SIZE [=] INT_VALUE
| TABLE_MODE [=] 'table_mode_value'
| auto_increment_cache_size [=] INT_VALUE
| AVG_ROW_LENGTH [=] value
| CHECKSUM [=] {0 | 1}
| CONNECTION [=] 'connect_string'
| {DATA | INDEX} DIRECTORY [=] 'absolute path to directory'
| DELAY_KEY_WRITE [=] {0 | 1}
| ENCRYPTION [=] {'Y' | 'N'}
| ENGINE [=] engine_name
| INSERT_METHOD [=] { NO | FIRST | LAST}
| MAX_ROWS [=] value
| MIN_ROWS [=] value
| PACK_KEYS [=] {0 | 1 | DEFAULT}
| PASSWORD [=] 'string'
| STATS_AUTO_RECALC [=] {DEFAULT | 0 | 1}
| STATS_PERSISTENT [=] {DEFAULT | 0 | 1}
| STATS_SAMPLE_PAGES [=] value
| UNION [=] (tbl_name[,tbl_name]...)
parallel_clause:
{NOPARALLEL | PARALLEL integer}
table_mode_value:
NORMAL
| QUEUING
| MODERATE
| SUPER
| EXTREME
partition_option:
PARTITION BY HASH(expression)
[subpartition_option] PARTITIONS partition_count
| PARTITION BY KEY([column_name_list])
[subpartition_option] PARTITIONS partition_count
| PARTITION BY RANGE {(expression) | COLUMNS (column_name_list)}
[subpartition_option] (range_partition_list)
| PARTITION BY LIST {(expression) | COLUMNS (column_name_list)}
[subpartition_option] PARTITIONS partition_count
subpartition_option:
SUBPARTITION BY HASH(expression)
SUBPARTITIONS subpartition_count
| SUBPARTITION BY KEY(column_name_list)
SUBPARTITIONS subpartition_count
| SUBPARTITION BY RANGE {(expression) | COLUMNS (column_name_list)}
(range_subpartition_list)
| SUBPARTITION BY LIST(expression)
range_partition_list:
range_partition [, range_partition ...]
range_partition:
PARTITION partition_name
VALUES LESS THAN {(expression_list) | MAXVALUE}
range_subpartition_list:
range_subpartition [, range_subpartition ...]
range_subpartition:
SUBPARTITION subpartition_name
VALUES LESS THAN {(expression_list) | MAXVALUE}
expression_list:
expression [, expression ...]
column_name_list:
column_name [, column_name ...]
partition_name_list:
partition_name [, partition_name ...]
partition_count | subpartition_count:
INT_VALUE
Parameters
| Parameter | Description |
|---|---|
| hint_options | The hint options.
NoticeIn the current version, the hint options for the |
| IF NOT EXISTS | If you specify IF NOT EXISTS, no error is returned even if the table to be created already exists. If you do not specify this clause and the table to be created already exists, an error is returned. |
| IGNORE | REPLACE | Optional. Specifies how to handle rows with duplicate unique key values when you execute the CREATE TABLE ... SELECT statement. If you do not specify IGNORE or REPLACE, an error is returned when rows with duplicate unique key values exist.
|
| PRIMARY KEY | Specifies the primary key of the table. If you do not specify this clause, a hidden primary key is used. OceanBase Database allows you to modify the primary key of a table or add a primary key to a table by using the ALTER TABLE statement. For more information, see ALTER TABLE. |
| FOREIGN KEY | Specifies the foreign key of the table. If you do not specify the foreign key name, the foreign key name is generated by concatenating the table name, OBFK, and the creation time. For example, the foreign key name created for the t1 table on August 1, 2021, 00:00:00 is t1_OBFK_1627747200000000. A foreign key allows cross-table references to related data. For more information, see reference_definition.
NoticeWhen you add a foreign key constraint, ensure that you have the |
| KEY | INDEX | Specifies the key or index of the table. If you do not specify the index name, the index name is generated by using the first column referenced by the index. If the index name is duplicated, the index name is generated by using the underscore (_) and a sequence number. For example, if the index name is duplicated when you create an index on the c1 column, the index name is c1_2. You can execute the SHOW INDEX statement to view the indexes on a table. |
| key_part | Creates a function index. |
| index_col_name | Specifies the column name of the index. You can specify ASC (ascending) after each column name. In the current version, only the descending (DESC) order of index columns is supported, and the ascending order does not take effect. By default, the ascending order is used. The index is sorted by the values in the first column specified in index_col_name. If the values in the first column are the same, the records are sorted by the values in the next column specified in index_col_name, and so on. |
| expr | A valid function index expression. You can specify a boolean expression, such as c1=c1.
NoticeIn the current version, you cannot create a function index on a generated column. |
| ROW_FORMAT | Specifies whether to enable the Encoding storage format.
|
| [GENERATED ALWAYS] AS (expr) [VIRTUAL | STORED] | Creates a generated column. expr specifies the expression for computing the column value.
|
| BLOCK_SIZE | Specifies the microblock size of the table. |
| lob_inrow_threshold | Specifies the INROW threshold for LOB fields. If the size of a LOB field exceeds this threshold, the excess data is stored in the LOB Meta table in OUTROW format. The default value is controlled by the ob_default_lob_inrow_threshold variable. |
| COMPRESSION | Specifies the compression algorithm of the table. Valid values:
|
| CHARSET | CHARACTER SET | Specifies the default character set of the columns in the table. For more information about the supported character sets, see Character set. |
| COLLATE | Specifies the default collation of the columns in the table. For more information about the supported collations, see Collation. |
| table_tablegroup | Specifies the tablegroup to which the table belongs. |
| AUTO_INCREMENT | Specifies the initial value for the auto-increment column in the table. OceanBase Database supports using auto-increment columns as partitioning keys. |
| comment | Comment. The maximum length of a comment is 1024 characters, and it is case-insensitive. |
| TTL | Time To Live, specifies the time after which data is deleted. For more information, see Delete expired data |
| PCTFREE | Specifies the percentage of space reserved for macroblocks. |
| parallel_clause | Specifies the parallelism level for the table:
|
| READ {ONLY | WRITE} | Specifies the read/write permissions for the table. The options are as follows:
|
| DUPLICATE_SCOPE | Specifies the properties of the replicated table. Valid values:
cluster level. |
| CHECK | Restricts the range of values in a column.
SHOW CREATE TABLE command.information_schema.TABLE_CONSTRAINTS view.information_schema.CHECK_CONSTRAINTS view. |
| constraint_name | The name of the constraint, which can contain up to 64 characters.
|
| expression | The constraint expression.
|
| KEY_BLOCK_SIZE [=] INT_VALUE | Optional. Specifies the size of the index key block in bytes, which controls the compression level of the table or index. This keyword is supported in the current version, but the feature is not available. |
| TABLE_MODE | Optional. Specifies the merge trigger threshold and merge strategy, which control the merge behavior after data is dumped. For more information, see table_mode_value. |
| auto_increment_cache_size | Optional. Specifies the number of cached auto-increment values. The default value is 0, indicating that the system will use the tenant-level configuration item (auto_increment_cache_size) as the cache size for the auto-increment column. |
| AVG_ROW_LENGTH [=] value | Optional. This keyword is supported in the current version, but the feature is not available. |
| CHECKSUM [=] {0 | 1} | Optional. This keyword is supported in the current version, but the feature is not available. |
| CONNECTION [=] 'connect_string' | Optional. This keyword is supported in the current version, but the feature is not available. |
| {DATA | INDEX} DIRECTORY [=] 'absolute path to directory' | Optional. This keyword is supported in the current version, but the feature is not available. |
| DELAY_KEY_WRITE [=] {0 | 1} | Optional. This keyword is supported in the current version, but the feature is not available. |
| ENCRYPTION [=] {'Y' | 'N'} | Optional. This keyword is supported in the current version, but the feature is not available. |
| ENGINE [=] engine_name | Optional. This keyword is supported in the current version, but the feature is not available. |
| INSERT_METHOD [=] { NO | FIRST | LAST} | Optional. This keyword is supported in the current version, but the feature is not available. |
| MAX_ROWS [=] value | Optional. This keyword is supported in the current version, but the feature is not available. |
| MIN_ROWS [=] value | Optional. This keyword is supported in the current version, but the feature is not available. |
| PACK_KEYS [=] {0 | 1 | DEFAULT} | Optional. This keyword is supported in the current version, but the feature is not available. |
| PASSWORD [=] 'string' | Optional. This keyword is supported in the current version, but the feature is not available. |
| STATS_AUTO_RECALC [=] {DEFAULT | 0 | 1} | Optional. This keyword is supported in the current version, but the feature is not available. |
| STATS_PERSISTENT [=] {DEFAULT | 0 | 1} | Optional. This keyword is supported in the current version, but the feature is not available. |
| STATS_SAMPLE_PAGES [=] value | Optional. This keyword is supported in the current version, but the feature is not available. |
| UNION [=] (tbl_name[,tbl_name]...) | Optional. This keyword is supported in the current version, but the feature is not available. |
| WITH PARSER parser_name | Optional. This keyword is supported in the current version, but the feature is not available. |
| COLUMN_FORMAT {FIXED | DYNAMIC | DEFAULT} | Optional. This keyword is supported only in the current version. The feature is not available. |
| STORAGE {DISK | MEMORY} | Optional. This keyword is supported only in the current version. The feature is not available. |
reference_definition
Note
When you add the reference_definition statement after a column definition, only the related syntax is supported, and the functionality does not take effect. For example, CREATE TABLE tb11(id INT PRIMARY KEY, sid INT REFERENCES tb11(id) MATCH FULL ON DELETE SET NULL); This statement can be executed successfully, but MATCH FULL and the behavior of the foreign key constraint (in this example, ON DELETE SET NULL) do not take effect. When you need to add a foreign key, use it in the Foreign Key clause. This behavior is compatible with MySQL 5.7.
REFERENCES tbl_name (key_part,...): specifies the primary table and columns to which the foreign key is associated.tbl_name: the name of the referenced table, which is the primary table to which the foreign key is associated.key_part: the name of the column in the referenced table, which is the column in the primary table to which the foreign key is associated. Usually, this is a column of the primary key or unique key.
match_action: specifies the matching method to be used during foreign key constraint checks, such as simple, full, or partial.MATCH SIMPLE: the default value. If any column in the foreign key isNULL, the foreign key constraint is not checked.MATCH FULL: all foreign key columns must be non-NULLvalues when the referenced foreign key columns are considered to match.MATCH PARTIAL: allows the foreign key to be partiallyNULL, and partial matches are also considered to satisfy the foreign key constraint.
opt_reference_option_list: defines how the foreign key table will respond when values in the primary table are deleted or updated. It includes the following options:ON DELETE: defines the action to be performed when rows in the primary table are deleted.ON UPDATE: defines the action to be performed when rows in the primary table are updated.
These options can be followed by the following actions:
RESTRICT: prevents the deletion or update of rows in the primary table.CASCADE: when rows in the primary table are deleted or updated, the corresponding rows in the foreign key table are also deleted or updated.SET NULL: sets the corresponding column in the foreign key toNULL(if the column allowsNULLvalues).NO ACTION: similar toRESTRICT.SET DEFAULT: sets the corresponding column in the foreign key to its default value (if the column has a default value).
table_mode_value
Note
Except for the NORMAL mode, all the listed TABLE_MODE modes represent QUEUING tables. A QUEUING table is the most basic table type. The following modes (except for the NORMAL mode) represent more aggressive compaction strategies.
NORMAL: the default value, indicating normal mode. In this mode, the probability of triggering a major compaction after data is dumped is very low.QUEUING: in this mode, the probability of triggering a major compaction after data is dumped is low.MODERATE: indicating moderate mode. In this mode, the probability of triggering a major compaction after data is dumped is moderate.SUPER: indicating super mode. In this mode, the probability of triggering a major compaction after data is dumped is high.EXTREME: indicating extreme mode. In this mode, the probability of triggering a major compaction after data is dumped is high.
For more information about major compactions, see Adaptive major compaction.
Examples
Create a database table.
obclient> CREATE TABLE tbl1 (c1 INT PRIMARY KEY, c2 VARCHAR(50)); Query OK, 0 rows affectedCreate a table with an index.
obclient> CREATE TABLE tbl2 (c1 INT PRIMARY KEY, c2 INT, c3 INT, INDEX i1 (c2)); Query OK, 0 rows affectedCreate a table
tbl3with a function index.obclient> CREATE TABLE tbl3 (c1 INT, c2 INT, INDEX i1 ((c1+1)), UNIQUE KEY ((c1+c2))); Query OK, 0 rows affected obclient> SHOW CREATE TABLE tbl3; +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | tbl3 | CREATE TABLE `tbl3` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL, UNIQUE KEY `functional_index` ((`c1` + `c2`)) BLOCK_SIZE 16384 LOCAL, KEY `i1` ((`c1` + 1)) BLOCK_SIZE 16384 LOCAL ) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+Create a table with 8 hash partitions.
obclient> CREATE TABLE tbl4 (c1 INT PRIMARY KEY, c2 INT) PARTITION BY HASH(c1) PARTITIONS 8; Query OK, 0 rows affectedCreate a table with range partitions as the top-level partitions and key partitions as the subpartitions.
obclient> CREATE TABLE tbl5 (c1 INT, c2 INT, c3 INT) PARTITION BY RANGE(c1) SUBPARTITION BY KEY(c2, c3) SUBPARTITIONS 5 (PARTITION p0 VALUES LESS THAN(0), PARTITION p1 VALUES LESS THAN(100)); Query OK, 0 rows affectedCreate a table with one column of type
gbkand one column of typeutf8.obclient> CREATE TABLE tbl6 (c1 VARCHAR(10), c2 VARCHAR(10) CHARSET GBK COLLATE gbk_bin) DEFAULT CHARSET utf8 COLLATE utf8mb4_general_ci; Query OK, 0 rows affectedEnable encoding and use
zstdcompression, with 5% space reserved for macroblocks.obclient> CREATE TABLE tbl7 (c1 INT, c2 INT, c3 VARCHAR(64)) COMPRESSION 'zstd_1.0' ROW_FORMAT DYNAMIC PCTFREE 5; Query OK, 0 rows affectedCreate a table
tbl8and set the parallelism to3.obclient> CREATE TABLE tbl8(c1 INT PRIMARY KEY, c2 INT) PARALLEL 3; Query OK, 0 rows affectedUse an auto-increment column as the partitioning key.
obclient> CREATE TABLE tbl9(inv_id BIGINT NOT NULL AUTO_INCREMENT,c1 BIGINT, PRIMARY KEY (inv_id) ) PARTITION BY HASH(inv_id) PARTITIONS 8; Query OK, 0 rows affectedSpecify a foreign key for the
ref_t2table. When anUPDATEoperation affects the key values in the parent table that match the rows in the child table, execute theSET NULLoperation.obclient> CREATE TABLE ref_t1(c1 INT PRIMARY KEY, C2 INT); Query OK, 0 rows affected obclient> CREATE TABLE ref_t2(c1 INT PRIMARY KEY, C2 INT,FOREIGN KEY(c2) REFERENCES ref_t1(c1) ON UPDATE SET NULL); Query OK, 0 rows affectedCreate a table
tbl10with aCHECKconstraint and view the constraint information.obclient> CREATE TABLE tbl10 (col1 INT, col2 INT, col3 INT, CONSTRAINT equal_check1 CHECK(col1 = col3 * 2)); Query OK, 0 rows affected obclient> SHOW CREATE TABLE tbl10; +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | tbl10 | CREATE TABLE `tbl10` ( `col1` int(11) DEFAULT NULL, `col2` int(11) DEFAULT NULL, `col3` int(11) DEFAULT NULL, CONSTRAINT `equal_check1` CHECK ((`col1` = (`col3` * 2))) ) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in setCreate a table
tbl11based on thetbl10table and view the table information.obclient> CREATE TABLE tbl11 LIKE tbl10; Query OK, 0 rows affected obclient> SHOW CREATE TABLE tbl11; +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | tbl11 | CREATE TABLE `tbl11` ( `col1` int(11) DEFAULT NULL, `col2` int(11) DEFAULT NULL, `col3` int(11) DEFAULT NULL, CONSTRAINT `tbl11_OBCHECK_1650793233327894` CHECK ((`col1` = (`col3` * 2))) ) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 | +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in setCreate a
cluster-level replicated tabledup_t1.Log in to the sys tenant and create a unit.
obclient> CREATE RESOURCE UNIT IF NOT EXISTS 2c5g MAX_CPU 2, MEMORY_SIZE '5G'; Query OK, 0 rows affectedCreate a resource pool with a unit number of 2.
obclient> CREATE RESOURCE POOL tenant_pool UNIT = '2c5g', UNIT_NUM = 2, ZONE_LIST = ('z1', 'z2', 'z3'); Query OK, 0 rows affectedCreate a user tenant
obmysqland specify the locality distribution.obclient> CREATE TENANT obmysql resource_pool_list=('tenant_pool'), LOCALITY = "F@z1, F@z2, R@z3", PRIMARY_ZONE = "z1" SET ob_tcp_invited_nodes='%'; Query OK, 0 rows affectedLog in to the
obmysqluser tenant created in step 3 and create a replicated table.obclient> USE test; Database changed obclient> CREATE TABLE dup_t1(c1 INT) DUPLICATE_SCOPE = 'cluster'; Query OK, 0 rows affected(Optional) View the broadcast log stream information. The replicated table will be created on this log stream.
obclient> SELECT * FROM oceanbase.DBA_OB_LS WHERE FLAG LIKE "%DUPLICATE%"; +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+-----------+ | LS_ID | STATUS | PRIMARY_ZONE | UNIT_GROUP_ID | LS_GROUP_ID | CREATE_SCN | DROP_SCN | SYNC_SCN | READABLE_SCN | FLAG | +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+-----------+ | 1003 | NORMAL | z1;z2 | 0 | 0 | 1683267390195713284 | NULL | 1683337744205408139 | 1683337744205408139 | DUPLICATE | +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+-----------+ 1 row in set(Optional) View the replica distribution of the replicated table under the sys tenant. The
REPLICA_TYPEfield indicates the replica type.obclient> SELECT TENANT_ID, DATABASE_NAME, TABLE_NAME, TABLE_ID, TABLE_TYPE, PARTITION_NAME, SUBPARTITION_NAME, INDEX_NAME, DATA_TABLE_ID, TABLET_ID, LS_ID, ZONE, SVR_IP, SVR_PORT, ROLE, REPLICA_TYPE, DUPLICATE_SCOPE FROM oceanbase.CDB_OB_TABLE_LOCATIONS WHERE TABLE_NAME = "dup_t1"; +-----------+---------------+------------+----------+------------+----------------+-------------------+------------+---------------+-----------+-------+------+----------------+----------+----------+--------------+-----------------+ | TENANT_ID | DATABASE_NAME | TABLE_NAME | TABLE_ID | TABLE_TYPE | PARTITION_NAME | SUBPARTITION_NAME | INDEX_NAME | DATA_TABLE_ID | TABLET_ID | LS_ID | ZONE | SVR_IP | SVR_PORT | ROLE | REPLICA_TYPE | DUPLICATE_SCOPE | +-----------+---------------+------------+----------+------------+----------------+-------------------+------------+---------------+-----------+-------+------+----------------+----------+----------+--------------+-----------------+ | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z1 | 11.xxx.xxx.xxx | 36125 | LEADER | FULL | CLUSTER | | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z1 | 11.xxx.xxx.xxx | 36124 | FOLLOWER | READONLY | CLUSTER | | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z2 | 11.xxx.xxx.xxx | 36127 | FOLLOWER | FULL | CLUSTER | | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z2 | 11.xxx.xxx.xxx | 36126 | FOLLOWER | READONLY | CLUSTER | | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z3 | 11.xxx.xxx.xxx | 36128 | FOLLOWER | READONLY | CLUSTER | | 1002 | test | dup_t1 | 500002 | USER TABLE | NULL | NULL | NULL | NULL | 200001 | 1003 | z3 | 11.xxx.xxx.xxx | 36129 | FOLLOWER | READONLY | CLUSTER | +-----------+---------------+------------+----------+------------+----------------+-------------------+------------+---------------+-----------+-------+------+----------------+----------+----------+--------------+-----------------+ 6 rows in setInsert and read and write data in the replicated table like a regular table. For a read request, if you use a proxy, the read request may be routed to any OBServer node; if you connect directly to an OBServer node, the read request will be executed on the connected OBServer node as long as the local replica is readable.
obclient> INSERT INTO dup_t1 VALUES(1); Query OK, 1 row affected obclient> SELECT * FROM dup_t1; +------+ | c1 | +------+ | 1 | +------+ 1 row in set
Create a table
tbl1with an integer columncol1, and specify that the operation uses 5 parallel threads. The data content of the new tabletbl1will be sourced from the query results of tabletbl2.CREATE /*+ parallel(5) */ TABLE tbl1 (col1 INT) AS SELECT col1 FROM tbl2;