Database base face questions (a)

Original link: http://www.cnblogs.com/cmgg/p/11150615.html

● Do you talk about database indexes

Reference answer:

Is the value of the index or columns in a database table for a configuration of ranking, fast access to specific information index database table. If you want a specific name by the staff to find him or her, then compared with the search for all rows in the table, the index helps to get information faster.

A major purpose of the index is to speed up the retrieval data table method, that can help searchers find information auxiliary data structure in line with the record ID restrictions as soon as possible.

● Do you talk about database transactions

Reference answer:

Database transaction (Database Transaction), refers to a series of operations performed by a single logical unit of work, or fully executed or not executed completely. Transaction processing ensures that all operations except within transactional units are completed successfully, or not permanently update the data - oriented resources. More reliable by the combination of a set of related operations as a unit either all succeed or all fail, error recovery can be simplified and application. To be a logical unit of work transaction, it must satisfy the so-called ACID (atomicity, consistency, isolation and durability) properties. A transaction is a logical database running work units shall be handled by the transaction manager of the DBMS subsystem is responsible for affairs.

● Do you talk about database transaction isolation

Reference answer:

The same time, only one transaction request for the same data, without any interference from each other between different transactions. For example, A is to withdraw money from a bank card, withdraw money before the end of the process A, B can not transfer money to the card.

● Do you talk about inner join and left join

Reference answer:

left join (left coupling) Returns includes all left table records and the right table join fields are equal recording right join (the right coupling) returns include all in the right table record and the left table join fields are equal recording
inner join (like value of the connection) returns only two rows of the table is equal to the coupling field

● Do things you chat database consistency

Reference answer:

Transaction (Transaction) system is a series of data for access to a program update operation consisting execution logic. DBMS transaction is the most basic unit, indivisible transaction.

Transaction has four basic characteristics, namely: Atomicity (Atomicity), consistency (Consistency), isolation (Isolation), persistent (the Duration), referred to as ACID.

1) Atomicity (Atomicity)

Atomicity refers to all operations in the transaction included either all succeed, or all fail rolled back, [delete delete delete] the operator of the transaction if successful, it must be fully applied to the database if the operation fails it can not have any impact on the database.

2) Consistency (Consistency)

Consistency means that the transaction must transform the database from one consistent state to another consistent state, that is to say before and after a transaction execution and implementation must be in a consistent state.

Take transfers, if both user A and user B money add up to a total of 5,000, no matter how transfers between A and B, turn several accounts, after the end of the transaction the money add up to two users should have 5000, which is transactional consistency.

3) Isolation (Isolation)

Isolation when a plurality of users concurrent access to the database, such as when operating with a table, a database for each user transaction open, operation not being disturbed by other transactions, for isolation between a plurality of concurrent transactions.

That is, to achieve such an effect: for any two concurrent transactions T1 and T2, T1 appears in the transaction, T2 or T1 has ended before the start, or started after the end of T1, so each transaction does not feel there are other matters to performing concurrently.

When concurrent access to multiple transactions, the transaction is between isolation, a transaction should not affect the operating results of other transactions. This means that in a concurrent environment, when different transactions while manipulating the same data, each transaction has its own full data space. Modifications made by concurrent transactions must modify the isolation to do with any other concurrent transactions.

Different isolation levels:

Read Uncommitted (read uncommitted [add Chinese Interpretation] content): the lowest level of isolation, nothing needs to be done, a transaction can read the results of another uncommitted transactions. All problems will occur concurrent transactions.

Read Committed (read submission): only after the transaction is committed, it will update the results seen by other transactions. You can solve the problem of dirty read.

Repeated Read (Repeatable read): in one transaction, read the results for the same data is always the same, regardless of whether there are other matters to this data whether the operation, as well as the transaction commits. Can solve dirty reads, non-repeatable reads.

Serialization (serialization): Transaction serialization execution, isolation highest level, at the expense of concurrency system. You can solve all the problems of concurrent transactions.

4) Persistent (Durability)

Persistence means that once a transaction is committed, then changes to the data in the database is permanent, commit the transaction will not be lost even in the case of a database system experienced a failure of the operation.

For example we use JDBC database operations, after the transaction is committed method, the user is prompted transaction is complete, when we complete the program execution until prompted, you can identify and correct the transaction submitted, even if this time the database there is a problem, it must To complete the full implementation of our business, otherwise it will cause us to see the prompt completion of the transaction, but because of the failure of major database without executing a transaction error.

 

 

 

● Tell us about what the index is that the index will be okay to pay more

Reference answer:

1, the index

Database queries in order to increase the index table speed of identifying a field added, the value is a structure of a database table in one or more columns to sort.

DB in the implementation of a Sql statement, the default mode is a full table scan based on search criteria, the matching conditions encountered Join the search result set. If we add a field by the index, the index list will go a query to locate specific number of rows value, greatly reducing the number of lines traverse the match, it can significantly increase the speed of queries.

advantage:

By creating a unique index, you can guarantee the uniqueness of each row of data in a database table.

It can greatly accelerate the speed of data retrieval, which is the main reason for creating the index.

You can accelerate the connection between the table and the table, especially in reference to particular interest for data integrity aspects.

When using packet data retrieval and sorting clause, can also significantly reduce the query time grouping and sorting.

By using the index, you can process the query, use concealer to optimize and improve the performance of the system.

Disadvantages:

Creating indexes and index maintenance takes time, this time with the increase in the amount of data increases.

The index needs to occupy physical space, in addition to the data table space outside the accounting data, each index also accounted for a certain physical space, if you want to build a clustered index, the space needs will be greater.

When the data in the table to add, delete and modify, the index should be dynamic maintenance, thus reducing the speed of data maintenance.

2, add an index principle

Rarely used or referenced in the query column should not create an index. This is because, since these columns rarely used, so there is no index or index does not improve query speed. On the contrary, due to the increase in the index, but reduces maintenance and increases the speed of the system space requirements.

Only a few columns of data should not increase the value of the index. This is because the values ​​of these columns is small, such as gender column personnel table, in the results of the query, the result set of data rows in a large proportion of rows of data tables that need to search for data in the table a large proportion of the line. Increase in the index, did not significantly speed up the retrieval speed.

Defined as text, image and bit data types of columns should not increase the index. This is because the amount of data in those columns either a large or small value.

When modifying performance is far greater than the retrieval performance, should not create the index. This is because, retrieval performance and performance modifications are conflicting. When the increase in the index will increase the retrieval performance, but reduces performance modifications. When the reduction of the index will be modified to improve performance and reduce retrieval performance. Therefore, when modifying the performance is far greater than the retrieval performance, should not create the index.

 

● Do you talk about database transactions and four properties

Reference answer:

Transaction (Transaction) system is a series of data for access to a program update operation consisting execution logic. DBMS transaction is the most basic unit, indivisible transaction.

Transaction has four basic characteristics, namely: Atomicity (Atomicity), consistency (Consistency), isolation (Isolation), persistent (the Duration), referred to as ACID.

1. Atomicity (Atomicity)

Atomicity refers to all operations in the transaction included either all succeed, or all fail rolled back, [delete delete delete] the operator of the transaction if successful, it must be fully applied to the database if the operation fails it can not have any impact on the database.

2. Consistency (Consistency)

Consistency means that the transaction must transform the database from one consistent state to another consistent state, that is to say before and after a transaction execution and implementation must be in a consistent state.

Take transfers, if both user A and user B money add up to a total of 5,000, no matter how transfers between A and B, turn several accounts, after the end of the transaction the money add up to two users should have 5000, which is transactional consistency.

3. Isolation (Isolation)

Isolation when a plurality of users concurrent access to the database, such as when operating with a table, a database for each user transaction open, operation not being disturbed by other transactions, for isolation between a plurality of concurrent transactions.

That is, to achieve such an effect: for any two concurrent transactions T1 and T2, T1 appears in the transaction, T2 or T1 has ended before the start, or started after the end of T1, so each transaction does not feel there are other matters to performing concurrently.

When concurrent access to multiple transactions, the transaction is between isolation, a transaction should not affect the operating results of other transactions.

This means that in a concurrent environment, when different transactions while manipulating the same data, each transaction has its own full data space. Modifications made by concurrent transactions must modify the isolation to do with any other concurrent transactions.

Different isolation levels:

Read Uncommitted (read uncommitted [add Chinese Interpretation] content): the lowest level of isolation, nothing needs to be done, a transaction can read the results of another uncommitted transactions. All problems will occur concurrent transactions.

Read Committed (read submission): only after the transaction is committed, it will update the results seen by other transactions. You can solve the problem of dirty read.

Repeated Read (Repeatable read): in one transaction, read the results for the same data is always the same, regardless of whether there are other matters to this data whether the operation, as well as the transaction commits. Can solve dirty reads, non-repeatable reads.

Serialization (serialization): Transaction serialization execution, isolation highest level, at the expense of concurrency system. You can solve all the problems of concurrent transactions.

4. Persistent (Durability Rev)

Persistence means that once a transaction is committed, then changes to the data in the database is permanent, commit the transaction will not be lost even in the case of a database system experienced a failure of the operation.

For example we use JDBC database operations, after the transaction is committed method, the user is prompted transaction is complete, when we complete the program execution until prompted, you can identify and correct the transaction submitted, even if this time the database there is a problem, it must To complete the full implementation of our business, otherwise it will cause us to see the prompt completion of the transaction, but because of the failure of major database without executing a transaction error.

 

● Do you talk about the three major paradigms database

Reference answer:

The first paradigm: When all the attributes of the relational schema R can no longer broken down into more basic data unit, said first normal form is R, i.e., attributes can not be separated

The second paradigm: R second normal mode R satisfies the relation if the first paradigm, and R have all non-primary attributes are totally dependent on the nature of the R key for each candidate, called

Third Pattern: Let R be a relational model of the first condition is satisfied Paradigm, R X is an arbitrary set of properties, if X is dependent on non-transmission of one candidate keyword any R, R, said third normal, i.e. non-primary property on the key code is not transmitted

● Can you explain the ACID properties of database

Reference answer:

1) Atomic: A transaction is regarded as the smallest indivisible unit, all the operations of things to be successful, or fail rollback, and the rollback can be done by logging, logging the modification operation performed by the firm, in the back reverse perform these modifications when rolling.

2) Consistency: database before and after the transaction execution are consistent state in a consistent state, the result of a transaction reads all data is the same.

3) Isolation: a firm to make changes before final submission, other transactions are missing.

4) Durability: Once a transaction commits, then modify the changes will be saved to the database forever.

Reproduced in: https: //www.cnblogs.com/cmgg/p/11150615.html

Guess you like

Origin blog.csdn.net/weixin_30438813/article/details/95069401