当前位置:网站首页>Concept of storage engine
Concept of storage engine
2022-07-06 01:58:00 【Crazy Stuka】
List of articles
- The concept of storage engine
- MyISAM Introduction to the characteristics of
- MylSAM Three different storage formats :
- lnnoDB characteristic
- Check out the storage engines supported by the system
- 2. Modify the storage engine
- InnoDB The relationship between row lock and index
- Deadlock
- How to avoid deadlock as much as possible ?
The concept of storage engine
MySQL The data in is stored in files with various technologies , Each technology uses a different storage mechanism 、 Indexing techniques 、 Lock levels and ultimately provide different functions and capabilities , These different technologies and supporting functions are in MySQL It's called storage engine in
The storage engine is MySQL Storage mode or storage format of data stored in file system
MySQL Common storage engines
MylSAM
lnnoDB
MyISAM Introduction to the characteristics of
MylSAM Unsupported transaction , Foreign key constraints are not supported either , Full text indexing only , Data files and index files are kept separately
Fast access , There is no requirement for transaction integrity MylSAM Suitable for inquiry 、 Insertion based applications
MylSAM Store three files on disk , The file name and table name are the same , But the extensions are :
.frm Definition of file storage table structure
The extension of the data file is .MYD (MYData)
The extension of the index file is .MYI (MYlndex)
Table level locking form , Lock the entire table when the data is updated
Databases block each other in the process of reading and writing
It will block the reading of user data in the process of data writing
It will also block the user's data writing in the process of data reading
Data is written or read separately , The process is fast and takes up less resources
MylSAM Three different storage formats :
(1) static state ( Fixed length ) surface
Static tables are the default storage format . Fields in static tables are immutable , So every record is a fixed length , The advantage of this storage method is that the storage is very fast , Easy to cache , It's easy to recover in case of failure ; The disadvantage is that it usually takes up more space than a dynamic table .
(2) Dynamic table
Dynamic tables contain variable fields , Records are not fixed length , The advantage of this storage is that it takes up less space , But frequent updates 、 Deleting records will cause fragmentation , It needs to be carried out on a regular basis OPTIMIZE TABLE Sentence or myisamchk -r Command to improve performance , And it's relatively difficult to recover in case of failure .
(3) Compression meter
The compressed table consists of myisamchk Tool creation , Take up a very small space , Because each record is compressed individually , So there's only a very small cost of access .
lnnoDB characteristic
Support transactions , Support 4 Transaction isolation levels
MySQL from 5.5.5 Version start , The default storage engine is InnoDB
Read and write blocking is related to transaction isolation level
It can cache indexes, data tables and primary keys very efficiently and store them in clusters
Support partition 、 Table space , similar oracle database
Support for foreign key constraints ,5.5 Full text indexing is not supported before ,5.5 After supporting full-text indexing, the hardware resource requirements are still relatively high
Row level locking , But full table scan will still be table level locking
lnnoDB The number of rows in the table is not saved , Such as select count(*) from table; when , lnnoDB Need to scan ─ Go through the whole table to calculate how many rows there are , however MylSAM Simply read out the number of saved lines . It should be noted that , When count(*) The statement contains where When the conditions MyISAM You also need to scan the entire table
For self growing fields ,InnoDB Must contain only the index of this field , But in MyISAM A combined index can be established with other fields in the table. When emptying the whole table ,InnoDB It's line by line deletion , Efficiency is very slow .MylSAM The table is rebuilt
Check out the storage engines supported by the system
show engines;
1. Look at the storage engine that the table uses
Method 1 :
show table status from Library name where name=' Table name '\G
Method 2 :
use Library name ;
show create table Table name ;
2. Modify the storage engine
(1). adopt alter table modify
use Library name ;
alter table Table name engine=MyISAM;
2. By modifying the /etc/my.cnf The configuration file , Specify the default storage engine and restart the service
3. adopt create table Specify the storage engine when creating the table
InnoDB The relationship between row lock and index
InnoDB Row locking is achieved by locking index entries , If there is no index ,InnoDB The record will be locked by a hidden cluster index .
Deadlock
Deadlocks are transactions waiting for each other's resources , Finally formed a loop .
Case study
create table t1(id int primary key,name char(3), age int);
insert into t1 values(1, 'aaa',22);
insert into t1 values(2, 'bbb',23);
insert into t1 values(3, 'aaa',24);
insert into t1 values(4, 'bbb',25);
insert into t1 values(5, 'ccc',26);
insert into t1 values(6, 'zzz',27);
conversation 1: conversation 2
beging; begin;
conversation 1
delete from t1 where id=5;
conversation 2
select * from t1 where id=1 for update;
conversation 1
delete from t1 where id=1; ## A deadlock occurs
conversation 2
update t1 set name='qqq' where id=5; ## A deadlock occurs
for update An exclusive lock can be placed on a row in the database , When the operation of a transaction is not completed , Other transactions can be read but not written or updated
How to avoid deadlock as much as possible ?
1) Access tables and rows in a fixed order .
2) Big business, small business . Big business tends to deadlock , If business permits , Break up big business into small ones .
3) In the same transaction , Try to lock all the resources you need at once , Reduce deadlock probability
4) Reduce isolation level . If business permits , Lowering the isolation level is also a good choice , Let's take the isolation level from Ra< Adjusted for Rc, A lot can be avoided because gap A deadlock caused by a lock .
5) Add a reasonable index to the table . If you do not use indexes, you will add locks to each row of records in the table , The probability of deadlock is greatly increased .
边栏推荐
- Mongodb problem set
- [the most complete in the whole network] |mysql explain full interpretation
- 2022年PMP项目管理考试敏捷知识点(8)
- Publish your own toolkit notes using NPM
- Computer graduation design PHP campus restaurant online ordering system
- Unreal browser plug-in
- Regular expressions: examples (1)
- 【Flask】静态文件与模板渲染
- Redis list
- 剑指 Offer 12. 矩阵中的路径
猜你喜欢
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Leetcode sum of two numbers
[Jiudu OJ 09] two points to find student information
干货!通过软硬件协同设计加速稀疏神经网络
Win10 add file extension
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
Publish your own toolkit notes using NPM
Unity learning notes -- 2D one-way platform production method
Docker compose configures MySQL and realizes remote connection
随机推荐
Leetcode skimming questions_ Invert vowels in a string
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Computer graduation design PHP campus restaurant online ordering system
Extracting key information from TrueType font files
Unity learning notes -- 2D one-way platform production method
竞赛题 2022-6-26
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
How to set an alias inside a bash shell script so that is it visible from the outside?
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
Shutter doctor: Xcode installation is incomplete
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Win10 add file extension
leetcode-2. Palindrome judgment
剑指 Offer 38. 字符串的排列
[flask] response, session and message flashing
Regular expressions: examples (1)
【全網最全】 |MySQL EXPLAIN 完全解讀
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
Dynamics 365 开发协作最佳实践思考
Format code_ What does formatting code mean