当前位置:网站首页>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 .
边栏推荐
- Win10 add file extension
- 3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
- 插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
- 02.Go语言开发环境配置
- Sword finger offer 12 Path in matrix
- [ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
- How does redis implement multiple zones?
- Computer graduation design PHP animation information website
- ClickOnce does not support request execution level 'requireAdministrator'
- Internship: unfamiliar annotations involved in the project code and their functions
猜你喜欢
Tensorflow customize the whole training process
Unity learning notes -- 2D one-way platform production method
Leetcode3, implémenter strstr ()
Pangolin Library: subgraph
Computer graduation design PHP animation information website
Force buckle 1020 Number of enclaves
Redis-列表
leetcode3、實現 strStr()
Redis-字符串类型
[flask] official tutorial -part3: blog blueprint, project installability
随机推荐
FTP server, ssh server (super brief)
Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
[Jiudu OJ 09] two points to find student information
Grabbing and sorting out external articles -- status bar [4]
[flask] static file and template rendering
C web page open WinForm exe
Text editing VIM operation, file upload
SPI communication protocol
[flask] response, session and message flashing
Sword finger offer 12 Path in matrix
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
leetcode-2. Palindrome judgment
竞赛题 2022-6-26
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
Maya hollowed out modeling
【Flask】响应、session与Message Flashing
[detailed] several ways to quickly realize object mapping
Basic operations of databases and tables ----- unique constraints