Interview frequently asked collection - MySQL part

Quick Mysql Dafa
Please sign for MySQL Soul Ten
Company 7e5855850727ae26ebcfd60c7700ae53e311fa6ddb64b63bb9552 &scene=178&cur_album_id=1663134697297608707#rd

Mysql Deadly Serial 13 Question
https://mp.weixin.qq.com/s?__biz=MzUxODAzNDg4NQ==&mid=2247486042&idx=2&sn=c7fa1e63353f3da7f977ac15398cf106&scene=21#wechat_redirect

A small company: MySQL serial questions
https://mp.weixin.qq.com/s/AHO_pyZtTH71qoiRsvtRlw

A large factory in Hangzhou: MySQL serial questions (Part 2)
https://mp.weixin.qq.com/s/rZ8aH5DDH3zGmkVyfKT-zw

MySQL high-frequency interview questions
https://mp.weixin.qq.com/s/IqE6iTfGQ76OWX7bQIlTCg

MySQL25 Questions and 25 Answers of the Eleventh "Counter Attack into Dachang"
https://mp.weixin.qq.com/s/IiJYHoAxqTnqW0LfRAh2BQ

27 Questions and 27 Answers on MySQL, the twelfth episode of "Counter Attack into Dachang"
https://mp.weixin.qq.com/s/KGFui8AaqOoxGzcKBrJ5-g

On Ali's side, he gave several SQLs and asked how many tree search operations need to be performed?
https://mp.weixin.qq.com/s/TwDu2dS8EP31IVyv_Qc5Hw

MySQL 30,000-word essence summary + interview 100 questions
https://mp.weixin.qq.com/s/rPnQAA1u_CLNw_8t_uSU3w

I am little M, the boss is not a man
https://mp.weixin.qq.com/s/eGKGVfZSKnKTLdEF3Mxomw

My name is Xiao M, and I am determined to build a MySQL empire
https://mp.weixin.qq.com/s/krJ7vXnNHAp3oYeVKni06w

 Index Part
Detailed explanation of MySQL index (with 20 diagrams)
https://juejin.cn/post/6940230890958094344

Nine index knowledge points
https://juejin.cn/post/6923788859712995336

Understand all the knowledge points of MySQL index in one go
https://mp.weixin.qq.com/s/faOaXRQM8p0kwseSHaMCbg

I almost have to ask in the interview: What is the principle of your index design? How to avoid index failure?
https://mp.weixin.qq.com/s/wyotVRKbBJ7LGdqFSxZOFg

How to gracefully answer the interviewer's question about MySQL index
https://mp.weixin.qq.com/s/xaJg28qXCAC4XR2mTm4xUg

B-Tree and B+Tree
B-Tree Index
https://mp.weixin.qq.com/s?__biz=Mzg2NjE5NDQyOA==&mid=2247483790&idx=1&sn=bf573b66517bed97ac63c3869ee6cb8a&scene=19#wechat_redirect

MySQL index bottom layer: B+ tree detailed explanation
https://mp.weixin.qq.com/s/HQe8g1M5ytZYLx5vvaAYoQ

The difference between clustered index and non-clustered index
https://zhuanlan.zhihu.com/p/113917726

The Myisam engine uses a non-clustered index, the index is separated from the data, and the leaf node stores the address of the data.

Innodb uses a clustered index, the leaf nodes of the primary key index tree store real data, and the leaf nodes of the non-primary key index tree store the primary key value

For the implementation of the bottom layer of the index, why not choose red-black tree, B-tree, etc.?
https://zhuanlan.zhihu.com/p/113917726

Summarize

(1) Hash table cannot realize range search

(2) Binary search tree can realize range search, but the self-incrementing primary key causes the tree to degenerate into a linked list, and the search efficiency changes from O(logn) to O(n)

(3) Red-black tree uses rotation to adjust the balance of the tree, but it is not absolutely balanced, because the auto-increment primary key will cause the tree to tilt to the right.

(4) AVL tree is absolutely balanced, and the search efficiency is O(logn). But the tree is too high, and the number of disk IOs is still a lot. Therefore, it is necessary to store a little more data at each layer.

(5) B-tree nodes store data directly, and the search efficiency is O(h*logn), where h is the tree height, and n is the number of keywords for each node.

(6) B+ tree Non-leaf nodes store index addresses, because each layer can store more keywords, and the query efficiency is higher. The leaf nodes store real data, and the leaf nodes are connected by a linked list, so the range search efficiency is higher.

Let’s take the hit index as an example. InnoDB’s primary key is a clustered index, which adopts a b+ tree structure. Non-leaf nodes store the primary key and pointers to child nodes. Leaf nodes store the overall row data, which is ordered as a whole. Through the primary key scan, search according to the tree, and finally fall to the leaf node, hit and return. (Actually, one page of mysql has 16kb in detail, and a page actually has multiple rows of records. After hitting a page, the row record must be found through the row record index through binary points)

Why Indexes Can Improve Query Performance
https://mp.weixin.qq.com/s?__biz=MzUxODAzNDg4NQ==&mid=2247486903&idx=1&sn=1c6ca6817baa255265fc25dd69551179&scene=21#wechat_redirect

Database isolation level
(1) What problems does each level solve, and what problems still exist

Read Uncommitted (read uncommitted content)

At this isolation level, all transactions can see the execution results of other uncommitted transactions. This isolation level is rarely used in practical applications, because its performance is not much better than other levels. Reading uncommitted data is also called dirty reading (Dirty Read).

Read Committed

This is the default isolation level for most database systems (but not for MySQL). It satisfies the simple definition of isolation: a transaction can only see changes made by committed transactions. This isolation level also supports the so-called non-repeatable read (Nonrepeatable Read), because other instances of the same transaction may have new commits during the processing of this instance, so the same select may return different results.

Repeatable Read

This is MySQL's default transaction isolation level, which ensures that multiple instances of the same transaction will see the same data rows when they read data concurrently. But in theory, this can lead to another thorny problem: phantom read (Phantom Read). Simply put, phantom reading means that when a user reads a range of data rows, another transaction inserts a new row in the range. When the user reads the range of data rows again, it will find that there are new Phantom" line. The InnoDB and Falcon storage engines solve this problem through the multiversion concurrency control (MVCC, Multiversion Concurrency Control) mechanism.

Serializable

This is the highest isolation level, and it solves phantom reads by enforcing the ordering of transactions so that they cannot conflict with each other. In short, it adds a shared lock on each data row read. At this level, a large number of timeouts and lock contention can result. These four isolation levels are implemented using different lock types. If the same data is read, problems are prone to occur. For example:

Dirty Read: A transaction has updated a piece of data, and another transaction has read the same piece of data at this time. For some reason, the previous RollBack operation, the data read by the latter transaction will be would be incorrect.

Non-repeatable read (Non-repeatable read): The data is inconsistent between the two queries of a transaction. This may be due to the insertion of the original data updated by a transaction in the middle of the two query processes.

Phantom Read: The number of data items in the two queries of a transaction is inconsistent. For example, one transaction queries several columns (Row) of data, while another transaction inserts new columns of data at this time. Previously In the next query of the transaction, there are several columns of data that have not been queried. If the data inserted by another transaction is inserted at this time, an error will be reported.

//--------------------------------------------------------------------------

The relationship between transaction isolation level and lock in Innodb
https://tech.meituan.com/2014/08/20/innodb-lock.html

How to elegantly answer MySQL's transaction isolation level and locking mechanism?
https://mp.weixin.qq.com/s/P7EYVgK_d0BKT8KIx3QVPQ

One article to understand transactions + isolation level + blocking + deadlock
https://mp.weixin.qq.com/s/xQhKBS2QXJKasRfKp7vF0A

Primary key problem part
Mysql: small primary key, big problem
https://mp.weixin.qq.com/s/VQ6xNOu5Xfy5KSWhZWrgoQ

What to do if the auto-increment primary key ID is used up 
https://mp.weixin.qq.com/s/qEA1pC2pfh3xz9HuM8iIBg

The boss asked me: "Why do you set an auto-increment id when creating a table? Isn't it good to use the serial number as the primary key?" 
https://mp.weixin.qq.com/s/WWGDojXxHYWNk1xDWIOg_Q

The join part
Write a good Join statement, provided you understand these
https://mp.weixin.qq.com/s/8XuX9Su1qvHrMLWcQzKTaQ

Statement execution process
SQL statement execution process
https://juejin.cn/post/6944940454177669128/

How is the select query executed?
https://juejin.cn/post/6944940454177669128

How does the MySQL storage engine complete the execution of an update statement
https://mp.weixin.qq.com/s/nRd1P5T9Gpy5FvZGmUYFWA

Leftmost prefix matching principle
https://www.cnblogs.com/ljl150/p/12934071.html

Leftmost prefix matching principle: when retrieving data, start matching from the leftmost of the joint index

Create a joint index of (a, b), where a=1 and b=2 or b=2 and a=1 in the where condition will take the joint index (the query optimizer will change the order)

Why can't I go to the joint index directly using b=2?

The index tree of the joint index (a,b):

In the case of equal values ​​of a, the values ​​of b are arranged in order. That is, a is ordered globally in the index, while b is only ordered locally.

This is because the rule for MySQL to create a joint index is to first sort the leftmost first field of the joint index, based on the sorting of the first field, and then sort the second field. So there is no way to use the joint index just for the query condition of b=2.

Why create a joint index?

The joint index (a, b, c) is equivalent to establishing three indexes (a), (a, b), (a, b, c), which can reduce the size of the index file.
In some cases, back table operations can be avoided. For example, select a, b, c from table where a=1 and b=1 and c=1;
on the basis of enabling index pushdown, the joint index can avoid most of the back-to-table operations.
How to judge which part of the joint index is selected by the executor?

From the key_len field in explain


What are the undo logs and redo logs in the log part ?
Redo log redo log is the InnDB storage engine layer, used to ensure transaction security. Before the transaction is committed, each modification operation will record the changed data, and save the physical log-data, so as to prevent the time point when a failure occurs, and dirty pages are not written to the disk. When restarting mysql, it will be redo according to the redo log do to achieve transactional durability

The undo log rollback log saves a version of the data before the transaction occurs, which can be used for rollback, and also provides reading under multi-version concurrency control.

Ten pictures explain MySQL log
https://juejin.cn/post/6944940786970525727

Detailed explanation of InnoDB transaction log redo log and undo log g8-PWCDgorLCXLtVDzCcwcmZs*Dv66nQGOVQRLXXb2AvqAWabtZmRlTz1hd&new=
1

Redo log and binlog of MySQL log system
https://mp.weixin.qq.com/s?src=11×tamp=1618058979&ver=3000&signature=DT2TdF58XsczdhTSnDEmz1ZNkvX36STnISKrcSzT3dGxWEYbxwCsB51GidvZ94gnDocDn Y7XLv-3VyJlsIM7gTqxl3r4WzrauNd9ZN9hFEUk0WE81NnmMkKnVHmDZpms&new=1

Three MySQL logs that must be understood
https://juejin.cn/post/6941988998038421518

Update statement to redo log for in-depth understanding
https://mp.weixin.qq.com/s/A7-FBuT5Ep590v5YEZw3-A

Regarding the master-slave delay, an article will explain it to you!
https://mp.weixin.qq.com/s/dVDxnvBhKm_hVuRlBiecuQ

How to optimize the performance optimization of deep paging lookup
MySQL paging query 
https://www.cnblogs.com/scott/p/7995856.html

How does MySQL optimize large pagination queries?
https://zhuanlan.zhihu.com/p/82676130

MySQL deep paging problem and optimization plan: how to quickly paginate tens of millions of data 
https://segmentfault.com/a/1190000023912355

Application of SQL parsing in Meituan 
https://tech.meituan.com/2018/05/20/sql-parser-used-in-mtdp.html

MVCC Mechanism
About MVCC, I made a mistake before, this time I corrected it!
https://mp.weixin.qq.com/s?__biz=MzkzNTEwOTAxMA==&mid=2247489415&idx=1&sn=8abd08678fd291b9e0980e254356e106&chksm=c2b25f7af5c5d66c096cb8894c23e02fa 860a3f7d31260ce95a8af2691b768ba23cdec3dfa07&scene=178&cur_album_id=1512519209967271939#rd

MySQL transaction and MVCC principle
https://juejin.cn/post/6950105323797479460

How to implement isolation level of MySQL transaction and MVCC
https://mp.weixin.qq.com/s/CZHuGT4sKs_QHD_bv3BfAQ

What exactly is mvcc concurrent transaction management control? How is it implemented based on undo log + Read View
?

Interview must ask: Do you understand the MVCC mechanism
https://mp.weixin.qq.com/s/hrbnpPqNNJszObizYq0Q1w

MVCC learning from shallow to deep
https://mp.weixin.qq.com/s/jxM7n_4Or52_-MlB4aK9Bw

For the classification of common storage engines and locks necessary for interviews, please check
https://mp.weixin.qq.com/s/0NOyiX421Rols4ErfteUdg

InnoDB's solution to phantom reading -- LBCC&MVCC
https://mp.weixin.qq.com/s/4ncvGW7klk8pDLE5o4jhFw

How to optimize MySQL when reading more and writing less
https://mp.weixin.qq.com/s/7V6WHF9L7RAwpzQsMszZWA

Read and understand MySQL master-slave replication read-write separation 
https://mp.weixin.qq.com/s/qrUn9EkuVFwxS1I2lry4Kg

Explain part
explain | Do you really know how to use this peerless sword of index optimization?
https://mp.weixin.qq.com/s/IKRVjiI43s9e03StBL0yPQ

Detailed explanation of MySQL
https://mp.weixin.qq.com/s?src=11×tamp=1618057435&ver=3000&signature=DT2TdF58XsczdhTSnDEmz1ZNkvX36STnISKrcSzT3dFAXKsoE5pUS3fxTdBxewyl9GTceJg9PTpLBnl0QO wocgk0V1uGSY0qj7V13mAYCUPbtU0dlhae1ZULt59kRRMB&new=1

What is the MySQL execution plan (Explain keyword
https://mp.weixin.qq.com/s?src=11×tamp=1618057995&ver=3000&signature=7EIYFDudLv*Q8y5PTZFNinyYdLMRSSeK9KvzVeuTAJ6zrk0*LorvVA1It8O89iETgTxA78oJL-U AButI-5RwfC4P9Aa2wcHs4dB8xMdOGHhZ6G3r*0EVevPDhljNA0wq&new=1

Torture from the soul - do you know what an SQL execution plan is?
https://juejin.cn/post/6937494803877724173

The most complete Explain summary, SQL optimization is no longer difficult
https://mp.weixin.qq.com/s/twTghH8wTA_0uZghOdawkw

Lock
Mysql lock: soul seven torture
https://mp.weixin.qq.com/s/R7gN-dVA4LrVi5zy2LvG_Q

Analysis of common locking scenarios
https://mp.weixin.qq.com/s?__biz=Mzg2NjE5NDQyOA==&mid=2247484144&idx=1&sn=878e3628fa15278821a55717998a1c39&scene=21#wechat_redirect

Types of locks and locking principles
https://mp.weixin.qq.com/s?__biz=Mzg2NjE5NDQyOA==&mid=2247483991&idx=1&sn=309b79caa7ac6df004747c8999c62c0f&chksm=ce4fc4c4f9384dd2775ef118db7 db9d05848b7ddc717956df7e55a2d1750fe2ee3a6fc158837&scene=178&cur_album_id=1380661999012642817#rd

Echo1024 public account - mysql series
Have you confused query cache and BufferPool? talk about it!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483817&idx=1&sn=d19e5ce05cd9520d1becd7b6afa5e0be&chksm=ec18410cdb6fc81a2bc86184427536832c8 f8aff1daae1d1966afa0ff1af667d292ffe43a310&scene=178&cur_album_id=1598686914755280897#rd

Let’s talk about what is slow checking and how to monitor it? How to troubleshoot?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483764&idx=1&sn=332b5b05d931b06a64ab07982bfab794&chksm=ec1841d1db6fc8c732c1c78fce4f902730 5fd2590871038817f8386b5fc0b4a3e296b4970d30&scene=178&cur_album_id=1598686914755280897#rd

Do you know the LRU-List in the database buffer pool?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483875&idx=1&sn=60744026b460f40e95871b0ddb0b8eab&chksm=ec184146db6fc85009bf60c6561e6d090 86a2ca901f6e808a7525d6f2ed441bbc20aaeeab1a4&scene=178&cur_album_id=1598686914755280897#rd

Know Flush-List? By the way, let's talk about the flushing mechanism of dirty pages!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483881&idx=1&sn=f9a8a9d140b49278dfa8dd0d6b56ee91&chksm=ec18414cdb6fc85aca7c705267ca5a660e7ef d0540cdaa1045b50e0532521f38b9896fcc60a2&scene=178&cur_album_id=1598686914755280897#rd

Use eleven pictures to explain clearly what happens in BufferPool when you CRUD! And the optimization of BufferPool!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483905&idx=1&sn=ecabed40aa39b065f1d54149a85ab998&chksm=ec1842a4db6fcbb296f1dc3990607621e7f4 4d33591ae5b6857a8ccd0ee75db93c6d18017516&scene=178&cur_album_id=1598686914755280897#rd

Do you know about MySQL data pages? Let's talk about page splitting!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247483989&idx=1&sn=cffab3e55a82e37e1707eb386c79e70d&chksm=ec1842f0db6fcbe65a5b4d176a4cb36be8e0 7b4952b70a0d6c8a0d1e8503a0728a9bb6a75016&scene=178&cur_album_id=1598686914755280897#rd

Introduction undo log, truncate, and undo log how to help you roll back things?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484018&idx=1&sn=bc5f775c11fc998138da587760b64f99&chksm=ec1842d7db6fcbc10cdcb31bf867161f c8c0397b664b96e7bb29c18e29bc20970a1656de7a90&scene=178&cur_album_id=1598686914755280897#rd

I advise! This young man doesn't speak MVCC, rat tail juice!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484048&idx=1&sn=4d651758ef5268f4d0f2aacd8f917f33&chksm=ec184235db6fcb234566ea9756c268a1ea5 3efee1b5e13e495635a54b5e8272801fc962cc9da&scene=178&cur_album_id=1598686914755280897#rd

What is the legendary MySQL redo log? talk about it!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484219&idx=1&sn=118f3c5aa5975d6ad2c7431c7ef010ce&chksm=ec18439edb6fca885e73c21add15232fc4d98 bf9ecc2780b1e8eb31a389df203d4e3c5d75ad1&scene=178&cur_album_id=1598686914755280897#rd

What is the use of MySQL's bin log? Where? Who wrote it? How to configure?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484266&idx=1&sn=09f7a4f59575f9f2b2d6767b845f1eae&chksm=ec1843cfdb6fcad9451930ee09b47bd369 fa880a00752ad7e99b63e4168ee27d2cea39a1bb17&scene=178&cur_album_id=1598686914755280897#rd

What are the formats of bin log? What's the difference? Advantages and disadvantages? What format is used online?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484316&idx=1&sn=c1d8fed59e3a352f3960ce803983bb17&chksm=ec184339db6fca2f94c31d361bd133e7029 ce579010e4ccf92f1796a0effad773eebb3f4ed67&scene=178&cur_album_id=1598686914755280897#rd

The best on the whole network! MySQL two-phase commit series! none of them!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247484738&idx=1&sn=9ef0071470fd71b36d035e1e340a56a0&chksm=ec1845e7db6fccf1712e711b7cfdd14c29 25d3fd65450457712083afe83bfecf56795366714e&scene=178&cur_album_id=1598686914755280897#rd

Interview site: How much do you know about the difference between char and varchar?
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247486310&idx=1&sn=1a2775e8ff2f746428dc1053c7129c8e&chksm=ec184bc3db6fc2d52c4d493032c27864 92119e9a228c3dfb4c56235e1bf751a7247d127caa9b&scene=178&cur_album_id=1598686914755280897#rd

Interviewer: Come on! Let’s talk about insert buffer and change buffer of MySQL database
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=2247486614&idx=1&sn=0e70c282461d8eb7d11b84125cebbfa7&chksm=ec184c33db6fc5257 5877e7bbe51059ff0782114575c896fbd0b4f713b3cc94d2005700c3700&scene=178&cur_album_id=1598686914755280897#rd

This is a hydrology! Briefly describe the three major paradigms
563b889eb0bb2fe047a276e32e1e9ad5573f0a08fd6 &scene=178&cur_album_id=1598686914755280897#rd

Assault in front of you! 33 high-frequency database interview questions, you deserve it!
https://mp.weixin.qq.com/s?__biz=MzI5MDg4ODEzOA==&mid=100000921&idx=1&sn=19138dc8c209ecdcdaffd0b34aec447c&scene=19#wechat_redirect
———————————————
Copyright statement: this article It is an original article of CSDN blogger "SunAlwaysOnline", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/qq_33591903/article/details/115068771

Guess you like

Origin blog.csdn.net/eagle89/article/details/129893181