数据库知识,mysql索引原理
1:innodb底层实现原理:https://blog.csdn.net/u012978884/article/details/52416997
2:MySQL索引背后的数据结构及算法原理 http://blog.jobbole.com/24006/
3:B树,B+树,https://www.cnblogs.com/vincently/p/4526560.html
4:数据库使用B+树进行索引,B+树的插入删除都在叶子节点上进行。每个节点大小为一个page的大小,一般为4k,一个节点右多个关键字。
每个节点只保存索引信息,不保存记录信息,可以存放更多的key,数据更加紧密。 叶子节点用链表连接,一次遍历能都找到所有 的信息,有利于区间查找,范围查询,遍历。
为什么不用红黑树,因为红黑树的索引深度比较深。
5:B树相对于B树的优点,不用每次都查询到叶子节点。经常查询的可能离根节点更近。
6:
深入理解 MySQL 底层实现
https://blog.csdn.net/gitchat/article/details/78787837
7:索引失效的原因:
https://www.cnblogs.com/binyue/p/4058931.html
8: 数据库最左前缀,创建一个a,b,c索引,那么 除了b,c不可以用索引,其它组合都能用索引。但是a,c组合只能用到a的索引,c的索引用不上。和顺序无关。
https://blog.csdn.net/zly9923218/article/details/51330995
mysql> alter table newslist add index indexName(htmlid,pid,id);
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from newslist;
+--------+-----+----+-------+--------------+---------------------------------+
| htmlid | pid | id | title | date_created | titleImage |
+--------+-----+----+-------+--------------+---------------------------------+
| 231 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 232 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 233 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 234 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 235 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 236 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 237 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 238 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 239 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 244 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 254 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 264 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 274 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 284 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
| 294 | 1 | 1 | ��Ŀ | 2017-02-08 | http://www.shiyanshi.com/my.jpg |
+--------+-----+----+-------+--------------+---------------------------------+
15 rows in set mysql> explain select * from newslist where pid=1 and id=1;
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | newslist | ALL | NULL | NULL | NULL | NULL | 15 | Using where |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
1 row in set mysql> explain select * from newslist where htmlid=254 and pid=1 and id=1;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where htmlid=254 and id=1;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where htmlid=254 and pid=1;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where pid=1 and id=1;
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | newslist | ALL | NULL | NULL | NULL | NULL | 15 | Using where |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
1 row in set mysql> explain select * from newslist where pid=1 and htmlid=254;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where pid=1 and htmlid=254;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where id=1 and htmlid=254;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set mysql> explain select * from newslist where id=1 and pid=1;
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | newslist | ALL | NULL | NULL | NULL | NULL | 15 | Using where |
+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
1 row in set
mysql> explain select * from newslist where id=1 and pid=1 and htmlid=254;
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | newslist | const | PRIMARY,indexName | PRIMARY | 8 | const | 1 | |
+----+-------------+----------+-------+-------------------+---------+---------+-------+------+-------+
1 row in set
9:mysql行锁的实现, 对索引进行加行锁。 InnoDB这种行锁实现特点意味着:只有通过索引条件检索数据,InnoDB才使用行级锁,否则,InnoDB将使用表锁!
https://blog.csdn.net/alexdamiao/article/details/52049993
数据库知识,mysql索引原理的更多相关文章
- Mysql数据库知识-Mysql索引总结 mysql mysql数据库 mysql函数
mysql数据库知识-Mysql索引总结: 索引(Index)是帮助MySQL高效获取数据的数据结构. 下边是自己整理的资料与自己的学习总结,,做一个汇总. 一.真的有必要使用索引吗? 不是每一个性能 ...
- 重新学习MySQL数据库5:根据MySQL索引原理进行分析与优化
重新学习MySQL数据库5:根据MySQL索引原理进行分析与优化 一:Mysql原理与慢查询 MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能 ...
- MySQL索引原理及慢查询优化
原文:http://tech.meituan.com/mysql-index.html 一个慢查询引发的思考 select count(*) from task where status=2 and ...
- (转)MySQL索引原理及慢查询优化
转自美团技术博客,原文地址:http://tech.meituan.com/mysql-index.html 建索引的一些原则: 1.最左前缀匹配原则,非常重要的原则,mysql会一直向右匹配直到遇到 ...
- MySQL索引原理及慢查询优化 转载
原文地址: http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能 ...
- MySQL索引原理及慢查询优化(转)
add by zhj:这是美团点评技术团队的一篇文章,讲的挺不错的. 原文:http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰 ...
- 【转载】MySQL索引原理及慢查询优化
原文链接:美团点评技术团队:http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型 ...
- MySQL索引原理与慢查询优化
索引目的 索引的目的在于提高查询效率,可以类比字典,如果要查“mysql”这个单词,我们肯定需要定位到m字母,然后从下往下找到y字母,再找到剩下的sql.如果没有索引,那么你可能需要把所有单词看一遍才 ...
- 干货:MySQL 索引原理及慢查询优化
MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓"好马配好鞍",如何能够更好的使用它,已经成为开发工程师的必修 ...
- MySQL索引原理及慢查询优化(转自:美团tech)
背景 MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓“好马配好鞍”,如何能够更好的使用它,已经成为开发工程师的必修课,我们经常会 ...
随机推荐
- win7 安装 VMware 出错解决办法
win7旗舰版安装VMware,安装过程中发生了如下错误.系统提示:“You may not install this product in the root directory of any dri ...
- 在程序中使用命令行的方式来调用py文件
做这个主要是程序可以做到直接调用一个脚本,而不是从脚本中把类或者函数import出来这样调用,比如我们写的python命令行文件,让java来调用,让c++来调用,都是可以的.这样不需要整个语言都用p ...
- JBPM4.4_jBPM4.4的流程定义语言(设计流程)
1. jBPM4.4的流程定义语言(设计流程) 1.1. process(流程) 是.jpdl.xml的根元素,可以指定的属性有: 属性名 作用说明 name 流程定义的名称,用于显示. key 流程 ...
- django 错误分类及解决办法汇总
问题1:启动服务器后浏览器无法访问http://localhost:8000,访问被拒绝
- APP适配IOS8,iPhone6和Plus截图简要说明
本文转载至 http://blog.csdn.net/yongyinmg/article/details/41422873 原文:http://www.zcool.com.cn/article/ZMT ...
- 上传控件CSS用图片代替
<style type="text/css"> a.btn {width: 120px;height: 42px;overflow: hidden;display: b ...
- 【VUE】Mac下vue 开发环境搭建,以及目录结构
1 安装Node.js 参看 node.js环境安装 http://www.cnblogs.com/richerdyoung/p/7265786.html 2 安装淘宝镜像 npm install ...
- Linux性能监控——CPU,Memory,IO,Network
版权声明:本文由刘爽原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/107 来源:腾云阁 https://www.qclou ...
- SRC常见WEB漏洞系列之HTTP-HOST头攻击
一.背景: web程序需要知道网站的域名比较麻烦,需要使用HTTP的 host头字段: <?php _SERVER["HTTP_HOST"] ?> @app.route ...
- Express 框架的安装
从零开始用 Node.js 实现一个微博系统,功能包括路由控制.页面模板.数据库访问.用户注册.登录.用户会话等内容. Express 框架. MVC 设计模式. ejs 模板引擎 MongoDB 数 ...