不同于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. Top命令数据分析

    一.top命令详解 当前时间 20:27:12 当前系统运行时间 3:18秒 1个用户 系统负载平均长度为 0.00,0.00,0.00(分别为1分钟.5分钟.15分钟前到现在的平均值) 第二行为进程 ...

  2. 【转载】自定义View学习笔记之详解onMeasure

    网上对自定义View总结的文章都很多,但是自己还是写一篇,好记性不如多敲字! 其实自定义View就是三大流程,onMeasure.onLayout.onDraw.看名字就知道,onMeasure是用来 ...

  3. spring cloud微服务实战教程/pdf/视频/百度云资源

    资源站:http://www.supan.vip 点击进入直接查找资源: http://www.supan.vip/spring%20cloud微服务实战 <Spring Cloud微服务实战& ...

  4. zabbix--显示插件Graphtree

    zabbix配置显示插件Graphtree 网盘下载地址:https://pan.baidu.com/s/1HGALOq2z7XiVRxyb6ASAeQ   提取码:13vn Graphtree 安装 ...

  5. maven nexus 私服搭建 Windows版

    准备工作 已安装jdk,并配置好了环境变量 已安装maven,并配置好了环境变量 下载Nexus Repository OSS:https://www.sonatype.com/download-os ...

  6. BitMap 图片格式与Base64Image格式互转方法

    BitMap 图片格式与Base64Image格式互转方法 /// <summary> /// 图片转为base64编码的字符串 /// </summary> /// < ...

  7. “IOS11不再信赖WOSIGN证书”公众号运营者如何应对

    ptd->_thandle = (uintptr_t)(-1); {{}/*** 传入需要的参数,设置给*/{}给Fragment添加newInstance方法,将需要的参数传入,设置到bund ...

  8. URI与URL详解

    URL 与 URI 很多人会混淆这两个名词. URL:(Uniform/Universal Resource Locator 的缩写,统一资源定位符). URI:(Uniform Resource I ...

  9. day003-python初识

    基本的写代码流程:1.创建 xxx.py文件 注意:文件不要保存在中文的路径下,和文件名不要以中文命名. 2.写代码 a.注意两行文件头 #! /usr/bin/env python  # -*- c ...

  10. [Algorithm] 171. Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...