当前位置:网站首页>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
边栏推荐
- Great Cells & Counting Grids
- 牛客题目——用两个栈实现队列、包含min函数的栈、有效括号序列
- Opencv (II) -- basic image processing
- OpenCV(三)——图像分割
- Opencv (V) -- moving target recognition
- Data collection: skillfully using Bloom filter to extract data summary
- File类字节输入、输出流
- OpenCV(一)——图像基础知识
- LOJ 576 - "libreoj noi round 2" sign in game [line segment tree]
- Array analog linked list
猜你喜欢

Opencv (IV) -- image features and target detection

牛客题目——二叉搜索树与双向链表

Cvxpy - latest issue

Fast Planner - detailed explanation of kinetic astar

MPC5744p时钟模块

Data collection: skillfully using Bloom filter to extract data summary

D3.js create a cool arc

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

HowNet and Wanfang database download papers for free ----- several times faster than connecting to the school intranet (some schools Wanfang database does not support downloading)

codis集群部署
随机推荐
领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
OpenCV(五)——运动目标识别
Is low code the future of development? On low code platform
C语言之枚举和联合体
201403-1
excel skill
The 21st - -- the 30th time
Random number formula random
D3.js create a cool arc
mysql视图及存储过程
从零开始Blazor Server(1)--项目搭建
Configuration and application of gurobi in pycharm
MySQL—连表查询
使用百度飞桨EasyDL实现电商UGC图片自动分类
Unable to enter the function definition after transferring the IAR project folder to the directory
ROS - error in running.Py file in the project
Embedded interview
[cqoi2012] local minima & Mike and foam
string数字类型转换为千分位
The 31st --- the 52nd