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 of the |
| IF NOT EXISTS | If you specify IF NOT EXISTS, an error will not be returned even if the table to be created already exists. If you do not specify this option and the table to be created already exists, an error will be returned. |
| IGNORE | REPLACE | Optional. Specifies how to handle rows with duplicate unique key values when you use the CREATE TABLE ... SELECT statement. If you do not specify IGNORE or REPLACE, an error will be returned when rows with duplicate unique key values exist.
|
| PRIMARY KEY | Specifies the primary key of the created table. If you do not specify this option, a hidden primary key will be 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 created table. If you do not specify the foreign key name, the foreign key name will be generated as the table name + OBFK + the creation time. For example, the foreign key name of the t1 table created on August 1, 2021, 00:00:00 is t1_OBFK_1627747200000000. A foreign key allows cross-referencing related data across tables. For more information, see reference_definition.
NoticeWhen you add a foreign key constraint, make sure that the current user has the |
| KEY | INDEX | Specifies the key or index of the created table. If you do not specify the index name, the index name will be generated as the first column of the index reference. If the index name is duplicated, the index name will be generated as the column name + underscore (_) + the sequence number. For example, if the index name is duplicated when you create an index on the c1 column, the index name will be 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 order) after each column name. Currently, only the descending order (DESC) syntax is supported for function indexes, and the feature is not effective. The default is ascending order. The sorting method for creating an index is as follows: First, sort the data by the value of the first column in index_col_name. For records with the same value in this column, sort them by the value of the next column name. Repeat this process. |
| expr | Specifies a valid function index expression, which can be a boolean expression, such as c1=c1.
NoticeOceanBase Database does not allow you to create function indexes on generated columns in the current version. |
| ROW_FORMAT | Specifies whether to enable the Encoding storage format for the table.
|
| [GENERATED ALWAYS] AS (expr) [VIRTUAL | STORED] | Creates a generated column. expr specifies the expression used to calculate the column value.
|
| BLOCK_SIZE | Specifies the microblock size of the table. |
| lob_inrow_threshold | Specifies the INROW threshold for the LOB field. If the size of a LOB field exceeds this threshold, the excess data will be 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 for the table. Valid values:
|
| CHARSET | CHARACTER SET | Specifies the default character set for the columns in the table. For more information about the supported character sets, see Character set. |
| COLLATE | Specifies the default collation for 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 of the auto-increment column in the table. OceanBase Database supports using auto-increment columns as partitioning keys. |
| comment | Comments. The maximum length of a comment is 1024 characters, and the comment is case-insensitive. |
| TTL | Time To Live, specifies the time to live for 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 replication scope of the table. Valid values:
cluster-level replication. |
| 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 syntax is supported in the current version, but the feature is not available. |
| TABLE_MODE | Optional. Specifies the merge threshold and merge strategy, which control the behavior of data compaction after data is dumped. For more information about the values, see table_mode_value. |
| auto_increment_cache_size | Optional. Specifies the number of cached auto-increment values. The default value is 0, indicating that this parameter is not configured. In this case, the system uses the tenant-level parameter auto_increment_cache_size to set the cache size for the auto-increment column. |
| AVG_ROW_LENGTH [=] value | Optional. This syntax is supported in the current version, but the feature is not available. |
| CHECKSUM [=] {0 | 1} | Optional. This syntax is supported in the current version, but the feature is not available. |
| CONNECTION [=] 'connect_string' | Optional. This syntax is supported in the current version, but the feature is not available. |
| {DATA | INDEX} DIRECTORY [=] 'absolute path to directory' | Optional. This syntax is supported in the current version, but the feature is not available. |
| DELAY_KEY_WRITE [=] {0 | 1} | Optional. This syntax is supported in the current version, but the feature is not available. |
| ENCRYPTION [=] {'Y' | 'N'} | Optional. This syntax is supported in the current version, but the feature is not available. |
| ENGINE [=] engine_name | Optional. This syntax is supported in the current version, but the feature is not available. |
| INSERT_METHOD [=] { NO | FIRST | LAST} | Optional. This syntax is supported in the current version, but the feature is not available. |
| MAX_ROWS [=] value | Optional. This syntax is supported in the current version, but the feature is not available. |
| MIN_ROWS [=] value | Optional. This syntax is supported in the current version, but the feature is not available. |
| PACK_KEYS [=] {0 | 1 | DEFAULT} | Optional. This syntax is supported in the current version, but the feature is not available. |
| PASSWORD [=] 'string' | Optional. This syntax is supported in the current version, but the feature is not available. |
| STATS_AUTO_RECALC [=] {DEFAULT | 0 | 1} | Optional. This syntax is supported in the current version, but the feature is not available. |
| STATS_PERSISTENT [=] {DEFAULT | 0 | 1} | Optional. This syntax is supported in the current version, but the feature is not available. |
| STATS_SAMPLE_PAGES [=] value | Optional. This syntax is supported in the current version, but the feature is not available. |
| UNION [=] (tbl_name[,tbl_name]...) | Optional. This syntax is supported in the current version, but the feature is not available. |
| WITH PARSER parser_name | Optional. This syntax is supported in the current version, but the feature is not available. |
| COLUMN_FORMAT {FIXED | DYNAMIC | DEFAULT} | Optional. This syntax is supported in the current version, but the feature is not available. |
| STORAGE {DISK | MEMORY} | Optional. This syntax is supported in the current version, but the feature is not available. |
reference_definition
Note
When you add a 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 runs successfully, but MATCH FULL and the behavior of the foreign key constraint (in this case, ON DELETE SET NULL) do not take effect. When you want to add a foreign key, use the FOREIGN KEY clause. This behavior is compatible with MySQL 5.7.
REFERENCES tbl_name (key_part,...): Specifies the primary table and column to which the foreign key is associated.tbl_name: The name of the referenced table, i.e., the primary table to which the foreign key is associated.key_part: The name of the column in the referenced table, i.e., the column in the primary table to which the foreign key is associated. Typically, 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: simple, full, or partial.MATCH SIMPLE: 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. The options include the following:ON DELETE: Defines the action to be performed when a row in the primary table is deleted.ON UPDATE: Defines the action to be performed when a row in the primary table is updated.
These options can be followed by the following actions:
RESTRICT: Prevents the deletion or update of rows in the primary table.CASCADE: When a row in the primary table is deleted or updated, the corresponding row in the foreign key table is 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 other listed TABLE_MODE modes represent QUEUING tables. A QUEUING table is the most basic table type, and the following modes (except for the NORMAL mode) represent more aggressive compaction strategies.
NORMAL: Default value, indicating normal. 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: Indicates moderate. In this mode, the probability of triggering a major compaction after data is dumped is moderate.SUPER: Indicates super. In this mode, the probability of triggering a major compaction after data is dumped is high.EXTREME: Indicates extreme. 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 primary 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 a macroblock retention space of5%.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 partition 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 table
ref_t2. When anUPDATEoperation affects the parent table's key values that match the child table's rows, 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 the tabletbl10and 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 | UNIT_LIST | +-------+--------+--------------+---------------+-------------+---------------------+----------+---------------------+---------------------+-----------+-----------+ | 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/write data from the replicated table like a regular table. For a read request, if using a proxy, the request may be routed to any OBServer node; if directly connected to an OBServer node, the request will be executed on the connected 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. Also, specify that 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;