惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
博客园 - 叶小钗
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Privacy & Cybersecurity Law Blog
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
雷峰网
雷峰网
C
Cybersecurity and Infrastructure Security Agency CISA
Schneier on Security
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
美团技术团队
T
Tenable Blog
T
Threatpost
S
Security Affairs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
The Last Watchdog
The Last Watchdog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
A
Arctic Wolf
Attack and Defense Labs
Attack and Defense Labs
AWS News Blog
AWS News Blog
AI
AI
W
WeLiveSecurity
H
Help Net Security
G
Google Developers Blog
PCI Perspectives
PCI Perspectives
博客园_首页
S
Securelist
B
Blog RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Forbes - Security
Forbes - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
Lohrmann on Cybersecurity
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
C
CERT Recently Published Vulnerability Notes
H
Hacker News: Front Page
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Spread Privacy
Spread Privacy
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
博客园 - 司徒正美
Google Online Security Blog
Google Online Security Blog
T
The Blog of Author Tim Ferriss

博客园 - hu晓峰

记winform程序异常排查 记一次wpf 背景图的坑点 【Unity踩坑】Unity项目管理员权限问题(Unity is running as administrator ) 依赖注入 微服务聚合查询 libmodbus编译为64位动态库 一文读懂Modbus协议:工业设备的“普通话“通信指南 Mysql union与union all有什么区别? 理解Systemd服务重启策略:on-failure vs always Redis分布式锁正确的实现方法 C# 解决串口通讯中,返回数据不完整 字典Dictionary.Add不是把新的元素插入到字典最后面 c# Avalonia 架构开发跨平台应用 MySQL InnoDB损坏修复:使用innodb_force_recovery 整数取低字节 C#汉字-区位码相互转化类 avalonia在linux下运行出现Default font family name can't be null or empty问题的解决 ICMP timestamp请求响应漏洞CVE-1999-0524解决方法 详解mysql的for update 使用Redis的SETNX命令实现分布式锁 ASP.NET Core中如何对不同类型的用户进行区别限流
‌索引基数
hu晓峰 · 2025-01-09 · via 博客园 - hu晓峰

索引基数‌是指索引中不重复的索引值的数量。例如,某个数据列包含值1、2、3、4、5、1,那么它的基数就是5。索引基数越高,索引的工作效果越好,因为索引基数高意味着列中包含很多不同的值,重复的值很少,这样索引在查找数据时会更高效‌12。

索引基数的计算方式

索引基数的计算通常采用采样的方法。以InnoDB存储引擎为例,InnoDB会对B+Tree索引的8个叶子节点的信息进行统计。具体过程如下:

  1. 取得B+Tree所有叶子节点的数量,记为A。
  2. 随机选取B+Tree索引的8个叶子节点。
  3. 统计每个叶子节点的不同记录的条数,记为P1, P2, ..., P8。
  4. 根据采样计算出Cardinality的预估值:Cardinality = (P1 + P2 + ... + P8) * A / 8‌1。

索引基数的重要性

索引基数相对于数据表行数较高时,索引的工作效果最好。如果某数据列含有很多不同的年龄,索引会很快地分辨数据行。相反,如果某个数据列用于记录性别(只有“M”和“F”两种值),那么索引的用处就不大。如果值出现的几率几乎相等,无论搜索哪个值都可能得到一半的数据行,这种情况下最好根本不要使用索引,因为查询优化器会忽略索引,进行全表扫描‌12。

查看索引基数的方法

在MySQL中,可以通过以下SQL语句查看表的索引基数:

SHOW INDEX FROM table_name;

在结果中,Cardinality列展示了该索引对应的索引基数,这是一个估计值,不是准确值。因为在实际生产环境中,数据表的更新操作非常频繁,每次数据更新都会影响索引文件,如果每次更新都要进行统计会增加系统压力‌