首批通过分布式安全可靠测评,为关键业务系统打造
OceanBase 数据库 BLOB 列无法直接创建索引
更新时间:2026-05-22 08:56
问题描述
对于 OceanBase 数据库的 Oracle 模式和 MySQL 模式都存在这个问题,也即都不能在含有 BLOB 列的字段上直接建立索引。具体报错如下。
MySQL 模式下在 BLOB 列上创建本地索引、全局索引均报错。
obclient [test]> create table t1(id int primary key,r1 blob); Query OK, 0 rows affected (0.601 sec)obclient [test]> create index idx_r1 on t1(r1) local; ERROR 1167 (42000): The used storage engine can't index column 'r1'obclient [test]> create index gdx_r1 on t1(r1) global; ERROR 1167 (42000): The used storage engine can't index column 'r1'Oracle 模式下在 BLOB 列上创建本地索引、全局索引均报错。
obclient [SYS]> create table t1(id int primary key, r1 blob); Query OK, 0 rows affected (0.197 sec)obclient [SYS]> create index idx_r1 on t1(r1); ORA-02329: column 'R1' of datatype string cannot be unique or a primary keyobclient [SYS]> create index gdx_r1 on t1(r1) global; ORA-02329: column 'R1' of datatype string cannot be unique or a primary key
适用版本
OceanBase 数据库 V2.x 和 V3.x 版本。
问题原因
数据库目前版本功能限制。
解决方法
由于 BLOB 字段一般存储的数据都很大,不能直接全字段建立索引,需要变通的建立前缀索引来实现原先的建索引需求。
MySQL 模式解决方法为建立前缀索引。对于本地索引和全局索引均有效。
obclient [test]> create index idx_r1 on t1(r1(100)) local; Query OK, 0 rows affected (1.498 sec)obclient [test]> create index gdx_r1 on t1(r1(100)) global; Query OK, 0 rows affected (1.440 sec)Oracle 模式解决方法为建立函数索引。对于本地索引和全局索引均有效。
obclient [SYS]> create index idx_r1 on t1(substr(r1,1,100)); Query OK, 0 rows affected (1.012 sec)obclient [SYS]> create index gdx_r1 on t1(substr(r1,1,100)); Query OK, 0 rows affected (0.840 sec)