mysql 阅读

1.覆盖索引 covering index: https://blog.csdn.net/cckevincyh/article/details/119655516

2.pk must be a clustered index

normal index can be clusted index or secondary index (depend on the column we select)

being a clustered index, no need to return table, get the record 

being a secondary index, get the pk, and return table

https://cloud.tencent.com/developer/article/1631424

3. B+ tree https://www.xiaolincoding.com/mysql/index/page.html#innodb-%E6%98%AF%E5%A6%82%E4%BD%95%E5%AD%98%E5%82%A8%E6%95%B0%E6%8D%AE%E7%9A%84

4. 

 

count(1)、 count(*) 执行的时候等于count(0)、 count(主键字段)在执行的时候,如果表里存在二级索引,优化器就会选择二级索引进行扫描。

所以,如果要执行 count(1)、 count(*)、 count(主键字段) 时,尽量在数据表上建立二级索引,这样优化器会自动采用 key_len 最小的二级索引进行扫描,相比于扫描主键索引效率会高一些。

再来,就是不要使用 count(字段) 来统计记录个数,因为它的效率是最差的,会采用全表扫描的方式来统计。如果你非要统计表中该字段不为 NULL 的记录个数,建议给这个字段建立一个二级索引。

5. super key, candidate key , pk

https://zhuanlan.zhihu.com/p/33394962

posted @ 2023-11-13 19:49  PEAR2020  阅读(30)  评论(0)    收藏  举报