假如有三个字段a,b,c,数据库记录有100万,那如果建a,b,c的联合索引,那这个联合索引的数量就应该是100万*100万*100万么,会不会也太大了,是不是说明联合索引的效率一般?
当前位置:网站首页>Mysql InnoDB下联合索引的索引数量?
Mysql InnoDB下联合索引的索引数量?
2022-07-24 10:13:00 【segmentfault】
采纳答案1:
InnoDB每组索引是一颗B+树,分为叶子节点和非叶子节点:非叶子节点只会存储索引列和指向下级节点的指针,而叶子节点存储的是真实数据页。
- 主键索引是一颗B+树,非叶子节点存储的是主键,叶子节点存储的是整行数据;
- 每组联合索引也是一棵B+树,非叶子节点存储的是索引值,叶子节点存储索引值和主键值;
所以题主问的索引数量不是字段数相乘的关系,无论联合了多少字段建索引,每条数据对应的叶子节点都是一个。
其他答案1:
InnoDB每组索引是一颗B+树,分为叶子节点和非叶子节点:非叶子节点只会存储索引列和指向下级节点的指针,而叶子节点存储的是真实数据页。
- 主键索引是一颗B+树,非叶子节点存储的是主键,叶子节点存储的是整行数据;
- 每组联合索引也是一棵B+树,非叶子节点存储的是索引值,叶子节点存储索引值和主键值;
所以题主问的索引数量不是字段数相乘的关系,无论联合了多少字段建索引,每条数据对应的叶子节点都是一个。
其他答案2:
联合索引是指由N个字段组成的键作为索引列形成的索引,并不是创建N个单独的索引
比如你这里的a、b、c,按该顺序组成的索引列就是(a,b,c),那么排序的时候就会逐一按每列的值进行排序,先排a,a一样的时候排b,b一样的时候排c,如下图
需要注意的是:联合索引中列的顺序可以是不一样的,(a,b,c)和(b,c,a)是不一样的,因为会根据最左匹配原则来进行匹配,比如查询的时候只有a一个条件,那么会走(a,b,c)这个索引,但是并不会走(b,c,a)
边栏推荐
- Spark Learning: Spark implementation of distcp
- Where is the bitbucket clone address
- Web page opening speed is very slow, how to solve it?
- [STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus
- The optimal time to buy and sell stocks includes the freezing period (leetcode-309)
- Aggregate log server
- Basic SQL operations
- The best time to buy and sell stocks includes handling charges (leetcode-714)
- Mysql8.0 authorized remote login
- Rust tokio:: task:: localset running mode
猜你喜欢

Scan line, weight segment tree

The heads of the five major international institutions called for urgent action to deal with the global food security crisis
![Cyclicbarrier and countdownlatch [concurrent programming]](/img/38/3305a0cdb6de40e1370cc93c8e5014.png)
Cyclicbarrier and countdownlatch [concurrent programming]

Spark Learning: implement compact table command
![CAS principle [concurrent programming]](/img/f0/77e7e1079f70198c601b0f1e25106e.png)
CAS principle [concurrent programming]

Raspberry Pie:: no space left on device

How to solve the problem of robot positioning and navigation in large indoor scenes with low-cost solutions?

Home raiding III (leetcode-337)

The most complete solution for distributed transactions
![Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.](/img/c3/d648cea4e8eef20a221dc034ecfc1d.png)
Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.
随机推荐
Binary original code, inverse code, complement code
【剑指 Offer II 115. 重建序列】
Arduino serial port information reading and output
Segment tree--
Spark Learning: how to choose different association forms and mechanisms?
Wechat applet
Mysql database JDBC programming
Installation UMI tutorial (error reporting and solutions)
Query about operating system security patch information
[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display
2022, will lead the implementation of operation and maintenance priority strategy
The best time to buy and sell stocks Ⅳ (leetcode-188)
Where is the bitbucket clone address
Deployment and analysis of coredns
MySQL query database capacity size
Aggregate log server
The paper of gaojingjian center was selected into the ACL 2022 of the international summit to further expand the privacy computing capacity of Chang'an chain
Raspberry Pie: /bin/sh: 1: bison: not found
An article takes you to understand the operation of C language files in simple terms
Arduino- use millis() to do two (or more) things at the same time