mysql中包含长字段索引的优化
不同于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 utf8mb3
character 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中包含长字段索引的优化的更多相关文章
- MySQL中 如何查询表名中包含某字段的表
查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where tabl ...
- MySQL中 如何查询表名中包含某字段的表 ,查询MySql数据库架构信息:数据库,表,表字段
--查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where ta ...
- 【整理】mysql中information_schema.tables字段说明
[整理]mysql中information_schema.tables字段说明 2016-05-04 16:47:50| 分类: 默认分类|举报|字号 订阅 下载LOFTER我的照片书 | ...
- mysql中走与不走索引的情况汇集(待全量实验)
说明 在MySQL中,并不是你建立了索引,并且你在SQL中使用到了该列,MySQL就肯定会使用到那些索引的,有一些情况很可能在你不知不觉中,你就“成功的避开了”MySQL的所有索引. 索引列参与计算 ...
- Mysql中主键与索引
摘自: https://www.cnblogs.com/wicub/p/5898286.html 一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没 ...
- mysql中的null字段值的处理及大小写问题
在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...
- Mysql中自增字段(AUTO_INCREMENT)的一些常识
Mysql中自增字段(AUTO_INCREMENT)的一些常识: http://chengxuyuan.naxieshir.com/fenlei/2/p/151.html
- mysql中查询一个字段属于哪一个数据库中的哪一个表的方式
mysql中查询一个字段具体是属于哪一个数据库的那一张表:用这条语句就能查询出来,其中 table_schema 是所在库, table_name 是所在表 --mysql中查询某一个字段名属于哪一个 ...
- Thinkphp中查询复杂sql查询表达式,如何表达MYSQL中的某字段不为空is not null?
Thinkphp中查询复杂sql查询表达式,如何表达MYSQL中的某字段不为空is not null?先上两种实现方式的实例:$querys["house_type_image"] ...
随机推荐
- AttributeError: module 'matplotlib' has no attribute 'verbose'
AttributeError: module 'matplotlib' has no attribute 'verbose' 翻译:attributeError:模块“matplotlib”没有“ve ...
- xenserver 备份和还原
1. 备份和还原xenserver host系统 //备份 # xe host-backup file-name=[name.xbk] -s [ip] -u [username] -pw [passw ...
- Django 之 Form 组件
常用功能 From 组件主要有以下几大功能: 生成 HTML 标签 验证用户数据(显示错误信息) HTML Form 提交保留上次提交数据 初始化页面显示内容 小试牛刀 下面我们通过 Form 组件来 ...
- 【Spring Cloud】Spring Cloud之Spring Cloud Sleuth,分布式服务跟踪(1)
一.Spring Cloud Sleuth组件的作用 为微服务架构增加分布式服务跟踪的能力,对于每个请求,进行全链路调用的跟踪,可以帮助我们快速发现错误根源以及监控分析每条请求链路上的性能瓶颈等. 二 ...
- 【Idea】idea中spring框架配置文件,无法自动提示spring配置
- win黑窗口命令
rd 删除 文件夹, 语法: rd [/S] [/Q] [drive:]path 参数: drive 盘符 path 文件路径 /S 递归删除文件夹( 删除前, 要确认是否进行删除) /Q 关闭 ...
- Httpd服务入门知识-Httpd服务常见配置案例之修改监听的IP和Port
Httpd服务入门知识-Httpd服务常见配置案例之修改监听的IP和Port 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看默认配置 [root@node101.yinzh ...
- iView学习笔记(三):表格搜索,过滤及隐藏列操作
iView学习笔记(三):表格搜索,过滤及隐藏某列操作 1.后端准备工作 环境说明 python版本:3.6.6 Django版本:1.11.8 数据库:MariaDB 5.5.60 新建Django ...
- @NotBlank注解地正确使用
@NotNull:不能为null,但可以为empty @NotEmpty:不能为null,而且长度必须大于0@NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度必 ...
- 推荐系统(recommender systems):预测电影评分--问题描述
推荐系统很重要的原因:1>它是机器学习的一个重要应用2>对于机器学习来说,特征是非常重要的,对于一些问题,存在一些算法能自动帮我选择一些优良的features,推荐系统就可以帮助我们做这样 ...