当前位置:网站首页>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
边栏推荐
- mysql视图及存储过程
- Scala branch control (single branch, double branch, multi branch), return value of branch judgment
- Three level cache of pictures in Android
- CODIS cluster deployment
- MPC_ ORCA
- 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)
- Bean: Model: Entity的区别
- Casadi -- detailed explanation of data types and introduction to basic operations
- CCF-201312-1
- C语言之指针进阶
猜你喜欢
随机推荐
json数据解析
Random number formula random
清晰的认识Torchvision(思维导图版)
使用百度飞桨EasyDL实现电商UGC图片自动分类
Leader: who uses redis overdue monitoring to close orders and get out of here!
Opencv (IV) -- image features and target detection
C语言之文件操作
合工大苍穹战队视觉组培训Day8——视觉,目标识别
Scala branch control (single branch, double branch, multi branch), return value of branch judgment
万字剖析Ribbon核心组件以及运行原理
Script file ‘D:\programs\anaconda3\Scripts\pip-script. py‘ is not present.
Handling of multiple parts with duplicate names and missing parts when importing SOLIDWORK assemblies into Adams
自然排序:comparable接口,定制排序:compartor接口的区别
Ten thousand words analysis ribbon core components and operation principle
Share a scheme of "redis" to realize "chat round system" that can't be found on the Internet
Casadi -- detailed explanation of data types and introduction to basic operations
牛客题目——最小的K个数
Cryptography series: certificate format representation of PKI X.509
密码学系列之:PKI的证书格式表示X.509
OpenCV(五)——运动目标识别








