当前位置:网站首页>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 .
边栏推荐
- Sword finger offer 38 Arrangement of strings
- Computer graduation design PHP college classroom application management system
- 国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
- Computer graduation design PHP animation information website
- Redis-Key的操作
- Kubernetes stateless application expansion and contraction capacity
- You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
- Regular expressions: examples (1)
- [Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
- Campus second-hand transaction based on wechat applet
猜你喜欢

How to improve the level of pinduoduo store? Dianyingtong came to tell you

How to upgrade kubernetes in place

Leetcode3, implémenter strstr ()

Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system

插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制

Tensorflow customize the whole training process

Poj2315 football games

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件

【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
随机推荐
Accelerating spark data access with alluxio in kubernetes
Internship: unfamiliar annotations involved in the project code and their functions
02. Go language development environment configuration
阿里测开面试题
Maya hollowed out modeling
A Cooperative Approach to Particle Swarm Optimization
Basic operations of databases and tables ----- non empty constraints
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
[flask] response, session and message flashing
leetcode-2. Palindrome judgment
Basic operations of database and table ----- set the fields of the table to be automatically added
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
NumPy 数组索引 切片
Flutter Doctor:Xcode 安装不完整
Cookie concept, basic use, principle, details and Chinese transmission
Sword finger offer 12 Path in matrix
[flask] official tutorial -part2: Blueprint - view, template, static file
dried food! Accelerating sparse neural network through hardware and software co design
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin