数据库知识,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凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓“好马配好鞍”,如何能够更好的使用它,已经成为开发工程师的必修课,我们经常会 ...
随机推荐
- c语言常用数据类型转换整理
你要发送原始数据流 还是 格式化输出? 如果是格式化 按原子说的 ,用sprintf / printf; 如果发送原始内存数据流, 可按下面发送, 发送 #define BYTE0(pointer) ...
- mysql 中实现行变列
前言: mysql行列变化,最难的就是将多个列变成多行,使用的比较多的是统计学中行变列,列变行,没有找到现成的函数或者语句,所以自己写了存储过程,使用动态sql来实现,应用业务场景,用户每个月都有使用 ...
- laravel 使用验证码
1)php.ini需要开两个扩展 extension=php_fileinfo.dllextension=php_gd2.dll 2)使用composer安装类包 composer require m ...
- 实例:用类来写一个 memcached 启动脚本
[root@localhost ~]$ yum install -y memcached #!/usr/bin/env python #-*- coding:utf-8 -*- import os i ...
- vsftpd配置教程
原文:http://www.cnblogs.com/hhuai/archive/2011/02/12/1952647.html 可能会遇到的问题: http://www.cnblogs.com/wea ...
- windows7中的“mklink命令”
从 Vista 以后,微软将用户文件和用户的软件配置( AppData ) 明确划分开,并且全部存放在使用者的用户目录下. Linux早已这样做了,并且在Linux中可将 home 挂载为独立分区,而 ...
- 《C++ Primer Plus》第15章 友元、异常和其他 学习笔记
友元使得能够为类开发更灵活的接口.类可以将其他函数.其他类和其他类的成员函数作为友元.在某些情况下,可能需要前向声明,需要特别注意类和方法声明的顺序,以正确地组合友元.潜逃类是在其他类中生命的类,它有 ...
- mysql show processlist 命令检查mysql lock
processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1. 进入mysql/bin目录下输入mysqladmin processlist; ...
- JS-随机div颜色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- LeetCode——Move Zeroes
Description: Given an array nums, write a function to move all 0's to the end of it while maintainin ...