当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Leetcode skimming questions_ Sum of squares

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

SPI communication protocol
![[flask] official tutorial -part2: Blueprint - view, template, static file](/img/bd/a736d45d7154119e75428f227af202.png)
[flask] official tutorial -part2: Blueprint - view, template, static file

How does redis implement multiple zones?

Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization

PHP campus financial management system for computer graduation design

安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3

Numpy array index slice

TrueType字体文件提取关键信息
随机推荐
【Flask】静态文件与模板渲染
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
Extracting key information from TrueType font files
[flask] response, session and message flashing
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
[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.
Regular expressions: examples (1)
Leetcode sum of two numbers
Leetcode skimming questions_ Invert vowels in a string
Flutter Doctor:Xcode 安装不完整
Internship: unfamiliar annotations involved in the project code and their functions
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Redis-Key的操作
D22:indeterminate equation (indefinite equation, translation + problem solution)
Basic operations of databases and tables ----- default constraints
Computer graduation design PHP college student human resources job recruitment network
LeetCode 322. Change exchange (dynamic planning)
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
Force buckle 1020 Number of enclaves
Leetcode3, implémenter strstr ()