数据库知识,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凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓“好马配好鞍”,如何能够更好的使用它,已经成为开发工程师的必修课,我们经常会 ...
随机推荐
- 如何使用ChemDraw改变说明文本
作为一款全球领先的化学绘图工具,ChemDraw能够绘制各种复杂的结构方程式.ChemDraw软件还增加了新的绘图工具,能够方便化学领域的图形绘制.本教程将向大家讲解如何在ChemDraw中改变说明文 ...
- 面试题:谈谈如何优化MYSQL数据库查询
1.优化数据类型 MySQL中数据类型有多种,如果你是一名DBA,正在按照优化的原则对数据类型进行严格的检查,但开发人员可能会选择他们认为最简单的方案,以加快编码速度,或者选择最明显的选择,因此,你可 ...
- swift - UIToolbar 的用法
代码如下: 1.声明及初始化 var toolsBar = UIToolbar() toolsBar.frame = CGRect(x:, y:, width:SCREEN_WIDTH, height ...
- Spring中通过构造方法传参数
1.实体类 package com.xbq.bean;import java.util.Timer; /** * @ClassName: Student * @Description: TODO 学生 ...
- hasattr() 、getattr() 、setattr()
hasattr(object, name) :用于判断一个对象中是否有指定的属性或方法,如果存在返回 True,否则返回 False getattr(object, name, [default]) ...
- Python 转义字符
转义字符 说明 \ 用在一行的末尾,表示续行符 \r 回车 \n 换行符 \\ 打印反斜杠 \' 打印单引号 \" 打 ...
- Spring学习笔记--构造器注入
之前讲到的名为"duke"的bean有一个私有成员变量beanBags代表这个杂技师bean的一次性能够抛出的最多的数量,Juggler有一个构造函数,构造函数的第一个参数(这里只 ...
- jquery单选框radio绑定click事件实现和是否选中的方法
使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1. ...
- \r\n和\n的区别
写Java代码的时候习惯用\r\n换行,这样可移植性比较好但是,在UVa - 160中就出现了错误,来看看是为什么吧. http://bbs.csdn.net/topics/220033879
- MySQL Server has gone away报错原因汇总分析(转自:http://cenalulu.github.io/mysql/mysql-has-gone-away/)
原因1. MySQL 服务宕了 判断是否属于这个原因的方法很简单,执行以下命令,查看mysql的运行时长 $ mysql -uroot -p -e "show global status l ...