查看InnoDB的磁盘空间利用率
这周阿里集团DBA内部分享时,支付宝的黄忠同学提了一个问题,关于InnoDB索引page 的利用率。 page 利用率 主要是指btee里面每个page的使用被使用的空间大
这周阿里集团DBA内部分享时,支付宝的黄忠同学提了一个问题,关于InnoDB索引page 的利用率。page利用率
主要是指btee里面每个page的使用被使用的空间大小。我们知道InnoDB默认一个page大小是16k。但实际使用情况不会总用满
我们定义为所有page的总使用字节除以总字节数。
在理论分析之前,我们要先弄个工具,查一下。
实例统计
写了一个简单的工具,读ibd文件上的每个page,算出每个page的实际使用字节,可以得到利用率。
我们找了线上一个库来模拟。表中有1个自增主键和3个非聚簇索引。不影响结论地简化为如下:
CREATE TABLE `ctu_factor_risk_99_03` ( `seq_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `a` varchar(32) DEFAULT NULL, `b` varchar(32) DEFAULT NULL, `c` varchar(32) DEFAULT NULL, KEY a (a), KEY bc (b,c), KEY cb (c,b), ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
插入数据中a,b,c均为长度为30字节的随机字符串。
显然主键和其他索引应该分开统计。统计结果发现,主键page利用率71%,其他索引利用率约52%。
简单分析
上面的结果很好理解。因为按照主键递增顺序插入数据,因此主键上数据“紧凑”。 而其他三个索引,则都是随机更新,需要不停地作索引节点分裂。
如何提升磁盘空间利用率
回到最开始的问题。其实我们关心的,是InnoDB为了保存相同的数据,用了多少空间。所以我们的问题变成,存储相同的数据,如何让占用的磁盘空间更小。
有一个很直观的结论。把这些索引删了重建,必然会减少空间消耗。因为这个操作之后,在新的数据插入之前,这些索引也变成“紧凑的”。
再建了一个与cb相同的索引,再跑,利用率居然高达98%。这个原理大家应该都知道了,只是量化一下而已。
工具附后, 用法 ./ibd_used tb.ibd N1 N2 >/tmp/r 最后几行为各个索引的利用率统计值

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When creating a virtual machine, you will be asked to select a disk type, you can select fixed disk or dynamic disk. What if you choose fixed disks and later realize you need dynamic disks, or vice versa? Good! You can convert one to the other. In this post, we will see how to convert VirtualBox fixed disk to dynamic disk and vice versa. A dynamic disk is a virtual hard disk that initially has a small size and grows in size as you store data in the virtual machine. Dynamic disks are very efficient at saving storage space because they only take up as much host storage space as needed. However, as disk capacity expands, your computer's performance may be slightly affected. Fixed disks and dynamic disks are commonly used in virtual machines

According to news from this website on August 5, Alibaba Cloud announced that the 2024 Yunqi Conference will be held in Yunqi Town, Hangzhou from September 19th to 21st. There will be a three-day main forum, 400 sub-forums and parallel topics, as well as nearly four Ten thousand square meters of exhibition area. Yunqi Conference is free and open to the public. From now on, the public can apply for free tickets through the official website of Yunqi Conference. An all-pass ticket of 5,000 yuan can be purchased. The ticket website is attached on this website: https://yunqi.aliyun.com/2024 /ticket-list According to reports, the Yunqi Conference originated in 2009 and was originally named the First China Website Development Forum. In 2011, it evolved into the Alibaba Cloud Developer Conference. In 2015, it was officially renamed the "Yunqi Conference" and has continued to successful move

1. First, click to open the Douyin app and click [Me]. 2. Click the three-dot icon in the upper right corner. 3. Click to enter [Settings]. 4. Click to open [Account and Security]. 5. Select and click [Log in to device management]. 6. Finally, click to select the device and click [Remove].

1. After turning on the phone, select NetEase Cloud Music. 2. After entering the homepage, you can see the [Ranking List] and click to enter. 3. In the ranking list, you can select any list and click [New Song List]. 4. Select your favorite song and click on it. 5. Return to the previous page to see more lists.

As a trading platform, Xianyu requires you to register and log in to your account before using it. Users can set an ID name for their account. What if they want to check what their ID is? Let’s find out together below! Introduction to how to view personal nicknames on Xianyu. First, start the Xianyu app. After entering the homepage, switch to the page of selling idle, messages, and me, and click the [My] option in the lower right corner. 2. Then on my page we need to click [Avatar] in the upper left corner; 2. Then when we go to the personal homepage page we can see different information, we need to click the [Edit Information] button here; 4. Finally click We can see it later on the page where we edit information;
![How to increase disk size in VirtualBox [Guide]](https://img.php.cn/upload/article/000/887/227/171064142025068.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
We often encounter situations where the predefined disk size has no room for more data? If you need more virtual machine hard disk space at a later stage, you must expand the virtual hard disk and partitions. In this post, we will see how to increase disk size in VirtualBox. Increasing the disk size in VirtualBox It is important to note that you may want to back up your virtual hard disk files before performing these operations, as there is always the possibility of something going wrong. It is always a good practice to have backups. However, the process usually works fine, just make sure to shut down your machine before continuing. There are two ways to increase disk size in VirtualBox. Expand VirtualBox disk size using GUI using CL

Kuaishou Live Companion is not only a powerful live broadcast auxiliary tool, but also a real-time insight platform for hot topics and trends created for broadcasters. Through this function, anchors can quickly capture the content that audiences are most concerned about, and then adjust the live content to make it more in line with the audience's tastes and interests. So how to check the hot video list in the Kuaishou Live Companion app? This tutorial guide will provide you with a detailed introduction to the steps. I hope it can help you. How to view the hot video list on Kuaishou Live Companion? The second step is to click on the daily video hot list. The third step is to check the daily video hot list.

Regardless of life or work, many people have long been deeply tied to WeChat and will be pulled into various groups at any time. So how many WeChat groups have you joined? You may immediately want to view the group chats in your address book, but only the WeChat groups you have saved in your address book will appear there, and other groups will not be visible. If you want to see all the WeChat groups you have joined, it is very simple: enter your nickname in the search box on the WeChat homepage, then find the group chat section in the search results, and click "More Group Chats" to view all related group chat information. Anyway, I was shocked. There were more than a hundred of them, and the scroll bar on the right became very small. Unfortunately, there is no specific number statistics... This method is also applicable to checking the QQ groups you have joined. PS: Some netizens also provided a trick:
