当前位置:网站首页>Database foundation
Database foundation
2022-07-27 16:56:00 【zhangzhang_ one】
List of articles
Database related concepts
data : Is the basic object stored in the database , For example, text 、 Images 、 Audio 、 video 、 Students' grades, etc .
database : It's stored in a computer for a long time 、 organized 、 Can share A collection of large amounts of data .
The data in the database is organized according to a certain data model 、 Describe and store .
have Less redundancy 、 High data independence And scalability , And Share for various users .In summary , The database has permanent storage 、 There are three basic characteristics of organization and sharing .Database management system (DataBase Management System,DBMS): It is a data management software between users and operating system , for example MySQL、Redis And so on are database management systems . Its main functions include : Data definition ( Define the composition and structure of data objects ); Data organization 、 Storage and management ; Data manipulation ( Add, delete, change, check, etc ); Database establishment and maintenance ; Transaction management and operation of database ( Secure data 、 Complete, etc ).
Database classification
According to the different data models used when storing data , There are two main types of databases : Relational database and Non relational database .
Relational database
Relational database It refers to the use of relational models ( That is, two-dimensional table format ) A database system for organizing data , It mainly includes data lines ( A record )、 Data columns ( Field )、 Data sheet ( Set of data rows )、 database ( Set of data tables ).
Mainstream relational databases include SQL Server、MySQL、PostgreSQL、SQLite wait .
Advantages of relational database :
- Easy to understand ( The two-dimensional table structure is very close to the concept of the logical world )
- Easy to use (SQL Language can easily operate relational databases )
- Easy to maintain ( The integrity constraint of the relationship reduces the probability of redundant data and data inconsistency )
Disadvantages of relational database :
- High concurrency support is insufficient
- Query efficiency is very low in massive data
- It's difficult to scale horizontally ( Adding service nodes is not easy , Downtime maintenance and data migration are often required )
- Poor performance ( Mainly because of the association query between multiple tables )
Non relational database
Aiming at the shortcomings of traditional relational database , In order to better adapt to the high concurrency of the Internet 、 High performance 、 The need for high availability and massive data challenges , There is a difference NoSQL(Non-relational SQL) database .NoSQL Give up the relational model and strong transaction guarantee , Focus on the high availability and scalability of the database .
NoSQL Database classification :
- Key value pair storage : The mainstream representative is Redis、Memcached
- Document storage : With relatively free content such as json To store document content , The mainstream representative is MongoDB
- Scalable record storage : Data is stored in records in , And can accommodate a large number of dynamic columns , The mainstream representative is HBase、Cassandra
- Graph storage : Store the data in the graph structure , The mainstream representative is Neo4j
Business
Concept
Business Is a user-defined sequence of database operations , All of these operations can be done , Or not at all , It is an indivisible work unit . For example, a SQL A statement can be a transaction .
The beginning and end of a transaction It can be displayed and controlled by the user , If the user does not define transactions explicitly , The database management system will automatically divide the transaction according to the default rules .
Transactions usually end with commit or rollback , Commit will write the updates to the database in the transaction back to disk , Rollback will undo all completed operations on the database in the transaction , Roll back to the state at the beginning of the transaction .
ACID
The transaction has the following 4 A feature :
- Atomicity (Atomicity): Transactions are treated as the smallest indivisible unit , All operations of the transaction are either committed successfully , Either all failures roll back .
Rollback can be implemented by rolling back the log , The rollback log records the modification performed by the transaction , Reverse these operations during rollback . - Uniformity (Consistency): The result of transaction execution must be to change the database from one consistency state to another .
- Isolation, (Isolation): The execution of a transaction cannot be interfered by other transactions , Or the modification made by a firm before submission , Is invisible to other transactions .
- persistence (Durability): Once the transaction is committed , Its changes will be permanently saved in the database , Even if the system crashes , The result of transaction execution should not be affected .
When the system crashes, redo logs can be used for recovery , To achieve persistence .
Concurrency consistency
In a concurrent environment , Concurrent execution of multiple transactions , The isolation between transactions is difficult to guarantee , As a result, there are many concurrent consistency problems :
- Missing changes : It refers to that the update operation of one transaction overrides the update operation of another transaction . For example, two transactions modify one data at the same time , The first transaction will take effect after being modified , The second transaction is then modified , The modification of the second transaction overrides the modification of the first transaction .
- Dirty reading : It means that the current transaction reads uncommitted data from another transaction , For example, affairs. T1 Modify a data without submitting , Business T2 Read this data , If T1 The amendment was withdrawn , that T2 The data read is dirty data .
- It can't be read repeatedly : It refers to reading the same data multiple times in a transaction , But the read data is inconsistent , Because in the meantime , Another transaction modifies this data .
- Fantasy reading : Illusory reading also belongs to the situation of unrepeatable reading in essence , It happens in T1 Read a range of data ,T2 Insert new data in this range ,T1 When reading the data in this range again , The reading result is different from the first reading .
The main reason of concurrency inconsistency is that the isolation of transaction is destroyed , The solution is : Ensure isolation through concurrency control .
Concurrency control can be achieved by blocking , But it needs user control , Very complicated .
Database management system provides The isolation level of the transaction , Make it easier for users to deal with concurrency consistency .
The isolation level of the transaction
- Uncommitted read : Changes in transactions , Even if it's not submitted , It's also visible to other things . Lowest isolation level , Can cause dirty reading 、 It can't be read repeatedly 、 Phantom reading .
- Submit to read : A transaction can only read the modifications made by the committed transaction . The default isolation level adopted by the large default database , Solved dirty reading .
- Repeatable : Ensure that the result of reading the same data multiple times in the same transaction is the same . Solve dirty reading and repeatable reading .
- Serializable : Force transactions to execute serially , Multiple transactions do not interfere with each other , There will be no concurrency consistency issues . The highest isolation level , Solve the above problem 4 A concurrency consistency problem , But this will lead to a decrease in concurrency , Poor performance . It is usually replaced by other concurrency level locking mechanisms .
Reference resources
Database system probability The first 5 edition
https://www.yisu.com/zixun/570175.html
http://www.cyc2018.xyz/%E6%95%B0%E6%8D%AE%E5%BA%93/
If there is any infringement , Please contact the author for deletion
边栏推荐
- 牛客题目——对称的二叉树
- Kubesphere multi node installation error
- String numeric type converted to thousands
- Insert pictures in word to maintain high DPI method
- Data collection: skillfully using Bloom filter to extract data summary
- LNMP环境--部署wordpress
- 【论文阅读】A CNN-Transformer Hybrid Approach for CropClassification Using MultitemporalMultisensor Images
- D3.js create a cool arc
- C语言之函数
- MPC_ ORCA
猜你喜欢

JD Zhang Zheng: practice and exploration of content understanding in advertising scenes

OpenCV(一)——图像基础知识

Rotate the whole model in ADAMS

CDQ divide and conquer and whole dichotomy learning notes

Clear understanding of torchvision (mind map)

The 21st - -- the 30th time

【论文阅读】A CNN-Transformer Hybrid Approach for CropClassification Using MultitemporalMultisensor Images

Scala for loop (loop guard, loop step size, loop nesting, introducing variables, loop return value, loop interrupt breaks)

Advanced pointer of C language

Automatic classification of e-commerce UGC pictures using Baidu PaddlePaddle easydl
随机推荐
Jerry's book can't find Bluetooth solutions [article]
Jerry's built-in touch parameters for modification [chapter]
获取当前时间的前N天和前后天的数组列表循环遍历每一天
Interpretation of C basic syntax: summarize some commonly used but easily confused functions (i++ and ++i) in the program (bit field)
CODIS cluster deployment
MQ Series 2: technology selection of Message Oriented Middleware
Character function, string function and memory function of C language
OpenCV(一)——图像基础知识
In addition to "adding machines", in fact, your micro service can be optimized like this
The class declared by the scala object keyword directly calls methods and associated objects
Layoff quarrel, musk: I'm too hard; Mercilessly open source a public opinion acquisition project; Feature engineering is as simple as parameter adjustment?! Nerf boss shouted that he couldn't move; Cu
京东张政:内容理解在广告场景下的实践和探索
Servlet用Cookie实现用户上次登录时间
Matplotlib drawing error: "! Latex error: file `type1cm.sty 'not found." solution
How to modify the decoding clock [chapter]
training on multiple GPUs pytorch
Gpt-2 text generation
Shardingsphere-proxy-5.0.0 distributed snowflake ID generation (III)
android中的图片三级缓存
被动收入:回归原始且安全的两种赚取方法