https://open.oceanbase.com/blog/13725359494
该链接中提到 mysql模式下,对于分区表,创建唯一索引时,如果指定了 LOCAL 关键字,则创建的是局部索引;如果指定了GLOBAL 关键字,则创建的是全局索引。
如果未指定 LOCAL 或 GLOBAL 关键字,默认创建的是全局索引。
测试环境(单zone 单机):https://www.oceanbase.com/demo/query-tenant-info
测试结果:分区表如果未指定 LOCAL 或 GLOBAL 关键字,默认创建的是 局部索引。 这个测试结果与上述链接中提到的“如果未指定 LOCAL 或 GLOBAL 关键字,默认创建的是 全局索引”不符! 这是什么原因导致的??????
测试内容如下:
[root@iZbp1eelqbnunqahxk48v8Z ~]#
[root@iZbp1eelqbnunqahxk48v8Z ~]#
[root@iZbp1eelqbnunqahxk48v8Z ~]# obclient -h127.0.0.1 -uroot@sys -P2881 -Dtestdb -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221487661
Server version: OceanBase_CE 4.2.1.0 (r100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959) (Built Sep 28 2023 07:25:28)
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
obclient [testdb]>
obclient [testdb]>
obclient [testdb]> drop table sales;
Query OK, 0 rows affected (0.051 sec)
obclient [testdb]> CREATE TABLE sales (
→ sale_id NUMBER,
→ product_id NUMBER,
→ customer_id NUMBER,
→ sale_date TIMESTAMP NOT NULL,
→ amount NUMBER
→ ) PARTITION BY RANGE(UNIX_TIMESTAMP(sale_date)) (
→ PARTITION p202301 VALUES LESS THAN(UNIX_TIMESTAMP(‘2023-02-01’)),
→ PARTITION p202302 VALUES LESS THAN(UNIX_TIMESTAMP(‘2023-03-01’)),
→ PARTITION p202303 VALUES LESS THAN(UNIX_TIMESTAMP(‘2023-04-01’))
→ );
Query OK, 0 rows affected (0.050 sec)
obclient [testdb]>
obclient [testdb]> show create table sales;
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sales | CREATE TABLE sales
(
sale_id
decimal(10,0) DEFAULT NULL,
product_id
decimal(10,0) DEFAULT NULL,
customer_id
decimal(10,0) DEFAULT NULL,
sale_date
timestamp NOT NULL,
amount
decimal(10,0) DEFAULT NULL
) 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
partition by range(UNIX_TIMESTAMP(sale_date))
(partition p202301 values less than (1675180800),
partition p202302 values less than (1677600000),
partition p202303 values less than (1680278400)) |
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.006 sec)
obclient [testdb]>
obclient [testdb]> create index ix_amount on sales(amount) local;
Query OK, 0 rows affected (0.247 sec)
obclient [testdb]> create index ix_customer_id on sales(customer_id) global;
Query OK, 0 rows affected (0.247 sec)
obclient [testdb]> create unique index ix_product_id on sales(product_id,sale_date);
Query OK, 0 rows affected (0.349 sec)
obclient [testdb]> create unique index ix_sale_date on sales(sale_date);
Query OK, 0 rows affected (0.348 sec)
obclient [testdb]>
obclient [testdb]> show create table sales;
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sales | CREATE TABLE sales
(
sale_id
decimal(10,0) DEFAULT NULL,
product_id
decimal(10,0) DEFAULT NULL,
customer_id
decimal(10,0) DEFAULT NULL,
sale_date
timestamp NOT NULL,
amount
decimal(10,0) DEFAULT NULL,
UNIQUE KEY ix_product_id
(product_id
, sale_date
) BLOCK_SIZE 16384 LOCAL,
UNIQUE KEY ix_sale_date
(sale_date
) BLOCK_SIZE 16384 LOCAL,
KEY ix_amount
(amount
) BLOCK_SIZE 16384 LOCAL,
KEY ix_customer_id
(customer_id
) BLOCK_SIZE 16384 GLOBAL
) 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
partition by range(UNIX_TIMESTAMP(sale_date))
(partition p202301 values less than (1675180800),
partition p202302 values less than (1677600000),
partition p202303 values less than (1680278400)) |
±------±-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.002 sec)
obclient [testdb]>