day05 database articles

1. Isolation level:
1. Uncommitted read
2. Dirty read: including dirty read, non-repeatable read, phantom read
3. Read committed
4. Non-repeatable read
5. Repeatable read
2. Storage engine
Common storage engines include InnoDB And MyISAM, and mermory, mysql default storage engine is InnoDB
InnoDB and MyISAM difference:
1. InnoDB supports transactions, MyISAM does not support transactions

2. InnoDB supports transaction rollback and current reading through undolog. MyISAM does not have undolog and redolog

3. InnoDB supports foreign keys, MyISAM does not support foreign keys

4. Because InnoDB is a clustered index, data and indexes are stored together, while MyISAM data and indexes are stored separately

 

 

Three, undolog and readlog

undolog:
Roll back data, record each change of data in units of behaviors, and a row of records has multiple versions coexisting
Multi-version concurrency control, that is, snapshot reading (also called consistent reading), allows query operations to access historical versions

The function of readlog: redo log is mainly to realize the persistence in ACID and ensure that the submitted data will not be lost

4. Locks
According to the granularity of locks, there are three kinds of locks.
Global locks: lock all tables in the database, which can be used for data backup. Before data backup is required, use global locks to lock all tables, and then perform backup operations. It can ensure the consistency of database data.
Table-level lock: each operation locks the entire table. The locking granularity is large, the probability of lock conflicts is the highest, and the concurrency is the lowest. It is used in
storage engines such as MyISAM, InnoDB, and BDB.
Row-level lock: Each operation locks the corresponding row data. The locking granularity is the smallest, the probability of lock conflicts is the lowest, and the concurrency is the highest. Applied
in the InnoDB storage engine.
V. Transaction
1. What is a transaction?
A transaction is a set of operations that either succeed or fail simultaneously.
2. Four major characteristics of transactions
2.1 Atomicity: An atomic operation either succeeds or fails at the same time
2.2 Consistency: The execution of the transaction cannot destroy the integrity and consistency of the database data, and the state of the data before and after the transaction execution remains consistent
2.3 Isolation : In a concurrent scenario, different transactions operate on the same data concurrently, each data has its own complete data space, and transactions are isolated from each other 2.4 Persistence: Once a
transaction is committed, the data changes in the database are permanent, even if the database crashes Downtime, data can be recovered after restarting the database
Six, database design

Use PowerDesinger to design the table structure based on the prototype diagram, and generate SQL statements for execution
VII. Index

1. The role of the index: the efficiency of submitting queries
2. Index classification:
ordinary index: the most basic index without any restrictions
Unique index: consistent with the ordinary index, the difference is that the value of the index column must be unique, but null values ​​are allowed , if it is a composite index, the combination of column values ​​must be unique.
Primary key index: It is a special index used to uniquely identify a record in the data table. Null values ​​are not allowed. Primary is generally used to constrain the joint
index: Combined index is also called composite index. The index built on multiple fields can quickly retrieve the
full-text index with compound query conditions: the full-text index that comes with the old version of MySQL can only be used for the data table of the database engine without MYISAM, and the new version of MySQL5. InnoDB 6 supports full-text indexing
Secondary index: Indexes created on fields other than the primary key are called secondary indexes. The indexed field value is used as the index data, and the leaf node also contains the primary key value
3. The underlying data structure of the index
3.1 B+Tree index: the most common index type, most indexes support B+ tree index.
3.2Hash index: only Memory engine support, easy to use scenarios. 
3.3S-Full-text (full-text index): Full-text index is also a special index type of MyISAM, mainly used for full-text index, InnoDB supports full-text index from Mysql5.6 version

5. Index creation principles
1). Create indexes for tables with large amounts of data and frequent queries.
2). Create indexes for fields that are often used as query conditions (where), sorting (order by), and grouping (group by)
.
3). Try to choose columns with high discrimination as the index, and try to build a unique index. The higher the discrimination, the higher the efficiency of using the index.
4). If it is a field of string type, the length of the field is relatively long, and a prefix index can be established according to the characteristics of the field.
5). Use joint indexes as much as possible to reduce single-column indexes. When querying, the joint index can cover the index in many cases, saving storage space
, avoiding table return, and improving query efficiency.
6). To control the number of indexes, the more indexes the better, the more indexes, the greater the cost of maintaining the index structure, which will affect the
efficiency of adding, deleting, and modifying.
7). If the index column cannot store NULL values, please use NOT NULL to constrain it when creating the table. When the optimizer knows whether each column
contains NULL values, it can better determine which index is most efficient to use for queries.

Eight, sql slow query steps
1. Open the slow query log
2. Query the slow query log information, analyze which sql execution statements are time-consuming
3. After finding the slow sql, you can use the EXPLAIN or DESC command to get how MySQL executes the SELECT statement information, including how and in what order the tables are joined during the execution of the SELECT statement. You can mainly judge whether SQL needs to be optimized based on several fields, especially whether it can hit the index or hit the index. 4.
Check whether select* or left join is used, one table is paired with multiple tables, and the table involved in the query Too many to locate and troubleshoot

9. What is a view and what is its main function?
A MySQL view (View) is a virtual table. Like a real table, a view is composed of columns and rows, but the view does not actually
exist in the database. The row and column data comes from the tables used in the query that defines the view, and is also dynamically
generated when the view is used.

10. Node
Root node: The topmost node of the tree. (There is only one root node)
Sub-nodes: In addition to the root node, nodes that are connected to nodes below themselves
Leaf nodes: Nodes that are no longer connected to nodes below themselves (that is, the end), called leaf nodes (also known as terminal nodes point). degree is 0

Guess you like

Origin blog.csdn.net/weixin_71921932/article/details/129988048