1.Base基础/3.Icon图标/操作/search备份
1.Base基础/3.Icon图标/操作/search备份
EN
文档
AntDB简介
快速入门
用户手册
登录数据库
建表
增删改查
执行计划
事务自动提交设置
数据安全
系统架构
最佳实践
参考指南
  • 文档首页 /
  • 用户手册 /
  • 建索引 /
  • 唯一索引

唯一索引

更新时间:2024-04-16 17:04:46
antdb=# create unique index idx_t_count_unique_id on t_count (id);
CREATE INDEX
antdb=# \di+ idx_t_count_unique_id
                                  List of relations
 Schema |         Name          | Type  | Owner  |  Table  |    Size    | Description 
--------+-----------------------+-------+--------+---------+------------+-------------
 public | idx_t_count_unique_id | index | danghb | t_count | 8192 bytes | 
(1 row)

目前由于AntDB的限制,在创建唯一索引的时候,唯一键须包含分片键,否则会创建失败:

antdb=# create unique index idx_t_count_unique_id on t_count (name);
ERROR:  Cannot create index whose evaluation cannot be enforced to remote nodes
antdb=#

带上分片键后再次执行:

antdb=# \d+ t_count
                                     Table "public.t_count"
 Column |     Type     | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+--------------+-----------+----------+---------+----------+--------------+-------------
 id     | numeric      |           |          |         | main     |              | 
 name   | varchar2(20) |           |          |         | extended |              | 
Indexes:
    "idx_t_count_unique_id" UNIQUE, btree (id)
    "idx_t_count_id" btree (id)
    "idx_t_count_id_name" btree (id, name)
Distribute By: HASH(id)
Location Nodes: db1_4, db2_2, db3_1
antdb=# create unique index idx_t_count_unique_name on t_count (name,id);
CREATE INDEX
antdb=# \di+ idx_t_count_unique_name
                                   List of relations
 Schema |          Name           | Type  | Owner  |  Table  |    Size    | Description 
--------+-------------------------+-------+--------+---------+------------+-------------
 public | idx_t_count_unique_name | index | danghb | t_count | 8192 bytes | 
(1 row)
问题反馈