不同于oracle,在mysql的Innodb存储引擎中,对索引的总长度有限制。在mysql 5.7中(https://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html),默认为3072。

If innodb_large_prefix is enabled (the default), the index key prefix limit is 3072 bytes for InnoDB tables that use DYNAMIC orCOMPRESSED row format. If innodb_large_prefix is disabled, the index key prefix limit is 767 bytes for tables of any row format.

innodb_large_prefix is deprecated and will be removed in a future release. innodb_large_prefix was introduced in MySQL 5.5 to disable large index key prefixes for compatibility with earlier versions of InnoDB that do not support large index key prefixes.

The index key prefix length limit is 767 bytes for InnoDB tables that use the REDUNDANT or COMPACT row format. For example, you might hit this limit with a column prefix index of more than 255 characters on a TEXT or VARCHAR column, assuming a utf8mb3character set and the maximum of 3 bytes for each character.

Attempting to use an index key prefix length that exceeds the limit returns an error. To avoid such errors in replication configurations, avoid enabling innodb_large_prefix on the master if it cannot also be enabled on slaves.

The limits that apply to index key prefixes also apply to full-column index keys.

所以在GBK编码中,最大可以到1536个字符,utf8/utf8mb3,1024个字符,utf8mb4为768个字符。这一限制为天然限制(mariadb因为采用Innodb引擎,该限制同样存在),无法绕开。

drop table big_index_test;
create table big_index_test(id int,content varchar(1000)) ROW_FORMAT=DYNAMIC CHARACTER set = utf8mb4 ;
create index idx_big_index on big_index_test(content);

[SQL]create index idx_big_index on big_index_test(content);
[Err] 1071 - Specified key was too long; max key length is 3072 bytes

相对于oracle来说,如果定义存在这种情况,即使记录没有或很少,仍然无法利用索引覆盖查询实现一些宽表的优化。

因此,对于mysql而言,对于一些定义很长的detail,最好的方式是垂直拆表,也就是将id和detail字段存储在单独的表中,然后业务代码中二次select的方式优化。如果detail字段是json类型的话,可以直接存储为json类型或存储在NoSQL中如mongodb。

注:当年5.6的时候,帮一个产品优化过mysql,mysql在大字段的处理上性能非常低下。

mysql中包含长字段索引的优化的更多相关文章

  1. MySQL中 如何查询表名中包含某字段的表

    查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where tabl ...

  2. MySQL中 如何查询表名中包含某字段的表 ,查询MySql数据库架构信息:数据库,表,表字段

    --查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where ta ...

  3. 【整理】mysql中information_schema.tables字段说明

    [整理]mysql中information_schema.tables字段说明 2016-05-04 16:47:50|  分类: 默认分类|举报|字号 订阅     下载LOFTER我的照片书  | ...

  4. mysql中走与不走索引的情况汇集(待全量实验)

    说明 在MySQL中,并不是你建立了索引,并且你在SQL中使用到了该列,MySQL就肯定会使用到那些索引的,有一些情况很可能在你不知不觉中,你就“成功的避开了”MySQL的所有索引. 索引列参与计算 ...

  5. Mysql中主键与索引

    摘自: https://www.cnblogs.com/wicub/p/5898286.html 一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没 ...

  6. mysql中的null字段值的处理及大小写问题

    在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...

  7. Mysql中自增字段(AUTO_INCREMENT)的一些常识

    Mysql中自增字段(AUTO_INCREMENT)的一些常识: http://chengxuyuan.naxieshir.com/fenlei/2/p/151.html

  8. mysql中查询一个字段属于哪一个数据库中的哪一个表的方式

    mysql中查询一个字段具体是属于哪一个数据库的那一张表:用这条语句就能查询出来,其中 table_schema 是所在库, table_name 是所在表 --mysql中查询某一个字段名属于哪一个 ...

  9. Thinkphp中查询复杂sql查询表达式,如何表达MYSQL中的某字段不为空is not null?

    Thinkphp中查询复杂sql查询表达式,如何表达MYSQL中的某字段不为空is not null?先上两种实现方式的实例:$querys["house_type_image"] ...

随机推荐

  1. Android-----创建SQLite数据库

    简单介绍一下Android系统内置轻便又功能强大的嵌入式数据库--SQLite. SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库引擎,它是一款轻型的数据库,是遵守ACID的关 ...

  2. idea注释类,方法

    1.添加类注释:file-settings-file and code Templates-Class #if (${PACKAGE_NAME} && ${PACKAGE_NAME} ...

  3. 标准库中的装饰器 lru_cache和全新的 singledispatch

    Python 内置了三个用于装饰方法的函数:property.classmethod 和 staticmethod. 另一个常见的装饰器是 functools.wraps,它的作用是协助构建行为 良好 ...

  4. [Startup].Linux启动时间优化

    转自:https://www.cnblogs.com/agui125/p/10070559.html 正文 回到顶部 1. 实践过程 我是对海思3559进行启动时间优化的.具体的操作可以参考<H ...

  5. deployment:声明式的升级应用

    9.1.使用RC实现滚动升级 #kubectl rolling-update kubia-v1 kubia-v2 --image=luksa/kubia:v2 使用kubia-v2版本应用来替换运行着 ...

  6. 数据结构中的堆(Heap)

    堆排序总结 这是排序,不是查找!!!查找去找二叉排序树等. 满二叉树一定是完全二叉树,但完全二叉树不一定是满二叉树. 构建顶堆: a.构造初始堆 b.从最后一层非叶节点开始调整,一直到根节点 c.如果 ...

  7. C++类库开发详解(转)

    前言:这是一篇总结性的文章,需要有一点C++和dll基本知识的基础,在网上查阅了很多资料感觉没有一篇详细.具体.全面的dll开发介绍,我这是根据最近项目和网上资料整理出来的,并附带实例的一个总结性的文 ...

  8. Window下安装Nignx并且使用文档

    1.下载nignx http://nginx.org/en/download.html         下载稳定版本,以nginx/Windows-1.12.2为例,直接下载 nginx-1.12.2 ...

  9. Easyui Datagrid扩展fixRownumber方法 转载

    $.extend($.fn.datagrid.methods, { fixRownumber : function (jq) { return jq.each(function () { var pa ...

  10. Mac下用命令行获取苹果手机的UDID

    在终端输入命令行:system_profiler SPUSBDataType | grep "Serial Number:.*" | sed s#".*Serial Nu ...