当前位置:网站首页>Several characteristics of MySQL database
Several characteristics of MySQL database
2022-06-23 07:15:00 【qq_ thirty-seven million two hundred and seventy-nine thousand 】
Reading guide :0. Storage engine MyISAM and InnoDB difference 1. Thing level 2. Clustered and non-clustered indexes 3. Back to the table 4.explain Implementation plan
0. Storage engine MyISAM and InnoDB difference
MyISAM
- Unsupported transaction , So every query is atomic ;
- Support table level lock , That is to say, every operation is to lock the whole table ;
- Store the total number of tables ;
- One MYISAM The table has three files : Index file 、 Table structure file 、 Data files ;
- Using nonclustered indexes (Non-clustered), The data field of the index file stores the pointer to the data file .
InnoDb
- Support ACID The business of ;
- Supports row level locks and foreign key constraints ;
- Do not store the total number ;
- One InnoDb The engine is stored in a file space ( Shared tablespace , Table size is not controlled by the operating system , A table may be distributed in multiple files ), It's also possible for multiple , Limited by operating system file size ;
- The primary key index adopts the clustered index ( The indexed data field stores the data file itself ), The data field of the secondary index stores the value of the primary key ; So look up the data from the secondary index , You need to find the primary key value through the secondary index first , Visit the secondary index ;
- Use auto increment primary key , Prevent data insertion , To maintain B+ Tree structure , A big adjustment of the document .
1. Thing level
Query isolation level :SHOW VARIABLES LIKE 'transaction_isolation%';
Read uncommitted Read uncommitted
Read uncommitted means that a transaction can be read without being committed , Obviously, this isolation level will lead to reading other uncommitted data , Once further processing is done based on the data read , Another transaction eventually rolls back the operation , Then the data will be messed up , And it's hard to track . On the whole , Reading uncommitted levels results in dirty reads .
Read the submission Read committed
As the name suggests, a transaction cannot be read until it is committed , Suppose you take a bank card to spend , Before you pay, you see that Cary has 2000 element , Your wife is shopping on Taobao at this time , I finished the payment ahead of you , At this time, when you pay again, you will be prompted that the balance is insufficient , But you can see that the money in the card is enough .
This is when two transactions are executed , Business A I read it at the beginning. The card has 2000 element , This is the time for business B Spend all the money on the card , Business A When we finally reconfirmed the balance, we found that the card had no money . Obviously , Read submit can solve the dirty read problem , But it can't be repeated .
Sql Server,Oracle The default isolation level for is Read committed.
Repeatable Repeatable read
Look at the name and you'll see , It is to solve the problem of non repeatable reading , Business A Once the execution starts , Regardless of business B How to change the data , Business A What you always read is the value it just started reading . So here's the problem , What if B hold id by 1 The data in the table is changed to 2, Business A Don't know id There is a change , When a transaction A When we added new data, we found that 2 Of id It already exists , This is unreal reading .
MySQL The default isolation level of is Repeatable read.
Serialization serializable
This is the most invincible existence , All the transactions are executed one by one , Because there is no concurrent scenario , What kind of unreal reading 、 Dirty reading 、 It's not repeatable. It doesn't exist . But again , Basic concurrency will be very poor . Final , In the end, the isolation level should be selected according to your own business scenario , No best , Only the most suitable .
2. Clustered and non-clustered indexes
Clustered index
- A table can only have one
- Stored records are physically continuous
- The leaf node is the data node , Stored data itself
Nonclustered indexes
- There are multiple tables in a table : General index , unique index , Full-text index
- Stored records are logically continuous , Physical storage is not continuous
- Leaf nodes are clustered indexes of data key, A pointer to the corresponding data block
3. Back to the table
The process of searching through a nonclustered index is to find the index first key Of the corresponding clustered index key, And then take the clustered index key Find the corresponding data on the primary key index tree
4.explain Implementation plan
4.1 select_type Column : Express SELECT The type of
Common values
- SIMPLE( A simple watch , That is, no table connection is used Or subquery ).
- PRIMARY( Main query , That is, the outer query )、UNION(UNION The second or The query statement after the user )
- SUBQUERY( First in subquery SELECT)
4.2 type Column : Indicates the connection type of the table
The connection types with good to poor performance are :
- system( There is only one row in the table , Constant table ).
- const( At most one matching row in a single table , for example primary key perhaps unique index).
- eq_ref( For each of the preceding lines , Only one record is queried in this table , Simply speaking , It is used in multi table connection primary key perhaps unique index).
- ref( And eq_ref similar , The difference is not to use primary key perhaps unique index, Instead, use a normal index ).
- ref_or_null( And ref similar , The difference is that the condition contains a pair of NULL Query for ).
- index_merge( Index merge optimization ).
- unique_subquery(in Is followed by a subquery that queries the primary key field ).
- index_subquery( And unique_subquery similar , The difference lies in in Is followed by a subquery that queries non unique index fields ).
- range( Range query in a single table ).
- index( For each of the preceding lines , All get data by querying the index ).
- all( For each of the preceding lines , They all get data through full table scanning ).
4.3 Extra: Description and description of the implementation
- Using index( This value represents mysql Will use overlay index , To avoid accessing tables ).
- Using where(mysql The storage engine will retrieve the rows before filtering , many where The condition refers to the columns in the index , When ( And if the ) When it reads the index , Can be tested by the storage engine , So not all belts where The query in clause will show “Using where”. Sometimes “Using where” The appearance of is a hint : Queries can benefit from different indexes ).
- Using temporary(mysql The temporary table is used to sort the query results ).
- Using filesort(mysql An external index will be used to sort the results , Instead of reading rows from the table in index order .mysql There are two file sorting algorithms , Both sorts can be done in memory or on disk ,explain I won't tell you mysql What sort of file will be used , It will not tell you whether the sorting will be done in memory or on disk ).
- Range checked for each record(index map: N) ( There's no good index , The new index will be reevaluated on each row of the join ,N Is shown in possible_keys Bitmap of index in column , And it's redundant ).
边栏推荐
- GINet
- About SQL: is there a way to fill in the null value in the field without adding fields on the basis of the original fields
- UNET code implementation
- 318. 最大单词长度乘积
- 20220621 Three Conjugates of Dual Quaternions
- Don't look for [12 super easy-to-use Google plug-ins are here] (are you sure you want to take a look?)
- 313. 超级丑数
- 【AI实战】机器学习数据处理之数据归一化、标准化
- 20220621 Dual Quaternion
- 别找了诸位 【十二款超级好用的谷歌插件都在这】(确定不来看看?)
猜你喜欢

yolov5检测小目标(附源码)

Initialization layer implementation

GINet

Deep learning series 47: Super sub model real esrgan

深度学习系列47:styleGAN总结

Regular expression graph and text ultra detailed summary without rote memorization (Part 1)

云原生落地进入深水区,博云容器云产品族释放四大价值

深度学习系列47:超分模型Real-ESRGAN

微信多人聊天及轮盘小游戏(websocket实现)

【博弈论】基础知识
随机推荐
898. subarray bitwise OR operation
301. 删除无效的括号
[system] right click the desktop icon. After turning around, the Explorer will crash and the desktop will be refreshed
【AI实战】xgb.XGBRegressor之多回归MultiOutputRegressor调参2(GPU训练模型)
Mysql事务隔离级别
初始化层实现
char和varchar区别
407-栈与队列(232.用栈实现队列、225. 用队列实现栈)
312. 戳气球
406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
Regular expression graph and text ultra detailed summary without rote memorization (Part 1)
OSI分层模型对工作的具体帮助
Verilog syntax explanation
Don't look for [12 super easy-to-use Google plug-ins are here] (are you sure you want to take a look?)
UNET code implementation
407 stack and queue (232. implementing queue with stack, 225. implementing stack with queue)
GINet
Pspnet complete code implementation
NPM download error NPM err code error
异构交易场景交互流程及一致性保证