---
title: 索引字段过长导致创建索引失败-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于 索引字段过长导致创建索引失败相关的常见问题和使用技巧，帮助您快速解决 索引字段过长导致创建索引失败的难题。
image: https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*OSPzQ6GUQF4AAAAAQHAAAAgAeiGDAQ/original
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# 索引字段过长导致创建索引失败

更新时间：2025-05-09 08:17

适用版本： V1.4.x、V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x、V4.3.x 内容类型：Troubleshoot  

## 问题现象

![image](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/knowledge-base/database/sql/20250304index-creation-failed-because-field-too-long.png)

## 问题原因

用户建表 SQL 如下。

```shell
CREATE TABLE `ut_table_with_list_partition_from_engine_os_ob` (

   `id` bigint(20) DEFAULT NULL,

   `name` varchar(8192) DEFAULT NULL,

   `sex` varchar(8192) 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 list columns(`sex`)

 (partition F values in ('F'));

```

索引字段最长为 16384 个字节，name 字段是 8192 个字符，按一个字符占 4 个字节，那么会超过 16384 个字节的限制。

## 适用版本

OceanBase 数据库所有社区版本。

## 解决方法

1. 确认 name 字段是否需要这么长的存储。
 2. 使用前缀索引的方式。

   ```shell
   CREATE INDEX `idx_ut_table_with_list_partition_from_engine_os_ob` ON `ut_table_with_list_partition_from_engine_os_ob` (name(10));
   Query OK, 0 rows affected (0.456 sec)

   ```

上一篇

[创建索引空间不足](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000003170692)

下一篇

[vector 列上创建索引时 coredump](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000002498846) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
