In summary database knowledge leftmost matching principle

1, the transaction

Transaction: Transaction is a set of operations to meet the ACID properties.

① atomic: either all operations in the transaction execution committed or rolled back

② consistency: consistent total transactions executed before and after data, more than 200 yuan is also not out of thin air out of thin air is not less 200

③ Isolation: operations in a transaction are not visible to other transactions submitted comments

③ permanent: Once the transaction is committed, permanent change data

2, the transaction isolation level

① uncommitted read: other transaction can read uncommitted data, also known as a dirty read

② non-repeatable read: read the results of the two are not the same

③ Repeatable Read (MYSQL Based default): When a transaction to read a recorded range, another transaction inserted in this range will produce a phantom read record

③ serial read: force the transaction serial execution

3, lock

Read-Write Lock

Read lock: also known as shared lock, in the same period of time, multiple users can simultaneously read the Uniform Resource

Write lock: Users get a write lock of blocking other users get read or write locks

Lock granularity divided by

  • Table-level lock: Small overhead, locking fast, will not deadlock. Lock large particle size, the highest probability of lock conflicts, the minimum amount of concurrency.
  • Row-level locking: large overhead, locking slow, there will be a deadlock. Lock efforts, small probability of lock conflicts, the highest degree of concurrency.

Optimistic and pessimistic locking lock

Optimistic locking: assuming that the execution is not consistency problem occurs if a problem occurs after the execution of monitoring the handler calls

Pessimistic locking: assuming that the execution will be consistency problems, must avoid locking.

If the frequency of conflict should be low selected optimistic locking, pessimistic locking high frequency is selected.

 4, clustered index and non-clustered indexes

Clustered index: is the leaf node data records.

Non-clustered index: leaf node record is the address of the data.

According to the primary key clustered index search efficiently, search by secondary index to search twice

5, hash index and the B + tree index

B +: data ordering, look for range

hash: suitable equivalent queries, data disorder

InNoDB storage engine for the B + tree frequently accessed data to establish hash index

6 difference, InNoDB with MyISAM index

①InNoDB primary index file and the data file is the same, MyISAM index and data file separated

②InNoDB secondary primary key index leaf node records, MyISAM index leaf node recorded data addresses

7, the index of the advantages and disadvantages

The advantage is that the index can improve query speed

The disadvantages of index insert operation to rebuild the index update

8, SQL optimization

 Try to use the index, splitting large query decomposition big link, returns only the necessary data.

9, the leftmost matching principle

Leftmost matching principle is for joint index, the joint index is a multi-value index, (a, b) can be understood as the first of a sort, in to b sort, if the conditions a value of a range, b can not use the index, a b is a particular value of the index can be utilized.

 10, the three paradigms

1NF  property can not be separated

2NF non-primary property is totally dependent on the code

Transmitting non-primary property dependent 3NF

11, tie

① the coupling connections are also called equivalent INNER JOIN

② The connection LEFT / RIGHT OUTER JOIN comprises no associated row, instead of not recording a NULL

③ special coupling NATURAL equivalent coupler remove duplicate column

④ Cartesian product join, it lacks significance generally do not

12, relational and non-relational databases

Relational

Two-dimensional table structure easier to understand

Support for SQL easy to operate

To pay the cost of support services is poor reading and writing performance

Non-relational

Distributed key-value pair storage structure

Does not support SQL

Good read and write performance

13, from the master copy

Using a primary database and a secondary database, the primary database operation to the log record, perform the same operation from the database, the primary database problem, from the database backup may be utilized.

Separate read and write, the primary database write operation, a read operation from the database, to reduce lock contention reduce the pressure in the master database.

14, the role of database connection pool

① resource reuse, avoid frequent create a connection release

② faster response times, ready to initialize

③ unified management link

15, char 与 varchar

char (n): fixed-length type, such as the definition (10), when you enter "abc" three characters, which accounts for 10 bytes of space or char, the other seven are null bytes.

chatr advantages: high efficiency; disadvantages: space; application scenarios: MD5 value storing passwords, fixed length, very suitable for use char.

varchar (n): a variable length, the value is stored together with the value of each byte is used to record occupies a byte length of its length.

Therefore, from the appropriate space considerations varcahr; char considered suitable from the efficiency, the use of both the trade-off.

16, with the difference InNoDB MyISAM engine

① matters: InNoDB support transactions, MyISAM does not support transactions

② lock mechanism: InNoDB row-level locking, MyISAM is table-level locking

③ Operation: MyISAM query operations faster (InNoDB to maintain many things), InNoDB insertion deletion faster

④ Foreign key: InNoDB support foreign keys

⑤Count (*): MyISAM directly read the saved row

17, deadlock

(1) four requirements Deadlock

Exclusive: the process of allocation of resources to the exclusive, and resources over time can only be used by a process

Not seize: Process possession of resources is not preempted

Possession and wait: a process occupy at least one resource and is waiting for a resource to be occupied by another process

Wait cycles: a plurality of resources each ring formation waiting

 

(2) deadlock mode processing

a deadlock prevention

Destroy not seize condition: has occupied the process can not seize resources, resource requests are not met, it has occupied the release of resources

Possession and wait: a one-time give enough resources, either to the full, or not to

Circular wait: for resource ordering, requests must be strictly increasing order request

b avoid deadlock

Check the system is in an unsafe state (banker's algorithm)

c detect deadlocks

A system for determining whether a deadlock

d lift the deadlock

Seize resources: seize sufficient resources from other processes, assigned to the process deadlock

Terminate the process: withdrawal of one or more process deadlock, cycle of destruction wait chain

 18, the horizontal and vertical sub-table sub-table

The level of sub-tables: record too much, we need to pay would be divided into a table, a hash modulo constitute a new table name.

Vertical Table: Record too long on the table in accordance with the close relationship between the degree of vertical columns segmentation.

19, multi-version concurrency control to solve the phantom read

Each start a transaction version number +1

SELECT: only to find rows of data than the current version number of small transactions, or delete the logo larger than the current version number

INSERT: Insert a new record keeping current version number

DELETE: Each row is deleted to save the current version as a cancellation mark

UPDATE: Insert a new record keeping the current version number, while preserving the current version number to identify the original row as deleted

20, How to check the version number of MySQL

SELECT  VERSION();

21, a data table seven Delete the last two

answer

INNoDB the maximum increment primary key recorded in memory

MyISAM the maximum increment primary key record in the data file

22, how to verify whether the index needs

Use explain how to view SQL query's execution

23. mysql troubleshooting Which means there?

View explain how to use SQL query execution

Turn on slow query log, see SQL

Recommended blog

relation between about mysql B + tree index, clustered index, non-clustered index, InnoDB, MyISAM parse

leftmost matching principle

the Java 208 most common interview questions: Seventeenth module answers

database common interview questions (with answers)

Guess you like

Origin www.cnblogs.com/mgblogs/p/11996817.html