当前位置:网站首页>MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database

MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database

2022-07-06 10:06:00 Office template library material frog

1、 Everything starts with the addition, deletion and modification of data

Okay , Until now , In fact, we have made a preliminary explanation MySQL Overall architecture design principle of , Everyone for MySQL What components are included inside , We usually update data and query data , Roughly how to do it , Have a relatively high-level understanding .

In addition, now we have a preliminary understanding MySQL After the architectural principle of , We also introduced some production experience related to our database , Is for any one project , Databases need to choose the right machine , At the same time, make pressure measurement , And there is a perfect visual monitoring system .

Now it can be understood that everyone has an available database , And I have a certain understanding of the overall architecture principle of the database . So next , We This column has 100 More content , Then, of course, we will explain all aspects of the database in detail

Which link should we start with ?

Of course, it starts with the addition, deletion and modification of the database , Because when you have a database in hand , You must develop a system , The system is directly based on the database Various operations of adding, deleting, modifying and querying , Implement various business logic

And when any system uses a database , It must start with inserting data , That is, first of all, we will add, delete and modify the data .

When you have data in your database , Then various query operations will be performed .

So the explanation order of our column , Just as you have a pressure tested 、 After having a perfect monitoring database , The system you developed uses the order of databases to Explain , First, explain the insider principle behind the system's various operations of adding, deleting and modifying databases , And the principle of affairs , Including the underlying mechanism of locks , Then explain that you have After the data , When performing various complex query operations , The underlying principles of indexing involved , The underlying principle of query optimization .

Of course, we will be interspersed with various cases of production practice , Just as I explained before 《 from 0 Start taking you to be JVM Real world Master 》 Like a column .

Then after explaining these , Let's talk about how we usually develop systems , How to model the database , When modeling the database , How to note Meaning field type 、 Some problems of index type , How to ensure that the database avoids deadlock 、 High performance operation .

Then we will explain some high-level database architecture design , For example, master-slave architecture design and sub database and sub table architecture design , Including some cases of production practice .

So these are the order that we will explain in the next column , I want to inform you in advance , In the process of actual explanation , It will increase a lot Rong , For example, the next few talks are in-depth analysis Buffer Pool The content of , In fact, there is nothing in the original outline .

In addition, in the process of my next explanation , The order of the original contents of the outline may also be adjusted at any time , For example, after I explain Buffer Pool after , And then maybe Will explain in depth directly redo logundo logbinlog These mechanisms , At the same time, we will explain the transaction mechanism , Locking mechanism , Underlying data storage mechanism .

Then after all this is said , Is to explain the content of indexing and query optimization , So I hope you can understand that we will make additional additions to the outline at any time , And me We will adjust the order of the outline content at any time .

good , Then start with this article , Let's explore various underlying mechanisms and production practice cases of databases !

2、 Take a look back. Buffer Pool What is it ?

Now let's review the Buffer Pool What is it ? In fact, it is a very critical component , Because we all know through the previous explanation One o'clock , That is, the data in the database is actually ultimately stored on disk files , As shown in the figure below .

             

But when we add, delete and modify the database , It is impossible to update the data on the disk directly , Because if you do random read and write to the disk , That speed It's quite slow , Random reading and writing of any large disk file , It may take hundreds of milliseconds . If you do that , Maybe your database can only Hundreds of requests have been processed !

We have explained it before , When you are adding, deleting or modifying the database , In fact, it is mainly for the memory Buffer Pool The data in , also In fact, you mainly add, delete and modify the data structure in the memory of the database , As shown in the figure below .

             

Of course , We have said before , In fact, everyone is worried about one thing , That is, you perform a lot of adding, deleting and modifying operations in the memory of the database , Memory data is updated , But at this time, if the database suddenly crashes , Then the updated data in the memory is gone ?

So in fact, we spent a lot of space on this issue at the beginning ,MySQL Afraid of this problem , So we introduced a redo log Mechanism , You are in the memory When adding, deleting and modifying data , At the same time, he will write the log corresponding to the addition, deletion and modification to redo log in , Here's the picture .

                                                                                                                                                             

In case your database suddenly crashes , No problem , As long as redo log Read out what additions, deletions and modifications you have done before in the log file , You can put this again in an instant Some additions, deletions and modifications are performed in your memory , This will restore what additions, deletions and modifications you have done before .

Of course, for the process of data update , He has a strict set of steps , Also involves undo logbinlog、 Commit transaction 、buffer pool Dirty data brush back disc , wait . We have talked about it before , I won't repeat it here , Just take you back to the database Buffer Pool This thing .

3Buffer Pool In one sentence

So here we are simply right Buffer Pool Make a summary of this thing , In fact, it is the first core component in the database that we must understand , Because adding, deleting, and changing operations The first thing to do is to target the Buffer Pool The data in the is executed , At the same time, it cooperates with the follow-up redo log、 Brush disk and other mechanisms and operations .

therefore Buffer Pool Is a memory component of the database , It caches the real data on the disk , And then our Java The addition, deletion and modification of the database performed by the system do , In fact, it is mainly executed on the cached data in the memory data structure .
In this article, we first discuss Buffer Pool Make a simple review of the positioning of this thing , In the next article, let's analyze Buffer Pool This memory data node What is included in the structure .

原网站

版权声明
本文为[Office template library material frog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060907389345.html