Baidu interview (Database isolation level, overload, override)

Source: Internet
Author: User

1. Isolation level of the database

ACID, refers to the four characteristics that a transaction (transaction) should have in a reliable database management System (DBMS): atomicity (atomicity), consistency (consistency), isolation (isolation), Persistence (durability).

READ UNCOMMITTED

READ Uncommitted is the least restrictive isolation level because the level ignores locks placed by other transactions. Transactions performed using the Read UNCOMMITTED level can read modified data values that have not yet been committed by other transactions, which are called dirty reads. This is because at the read uncommitted level, the read data does not require an S lock, so that it does not conflict with the X lock on the data being modified. For example, transaction 1 modifies a row, and transaction 2 reads this line before transaction 1 commits. If transaction 1 is rolled back, transaction 2 is enrolled in a row of uncommitted data, which we think is nonexistent.

READ COMMITTED

READ COMMITTED (nonrepeatable reads) is the default isolation level for SQL Server. This level prevents dirty reads by specifying that the statement cannot read data values that have been modified but not yet committed by other transactions. Between the execution of individual statements in the current transaction, other transactions can still modify, insert, or delete data, resulting in a read operation that cannot be repeated, or "shadow" data. For example, transaction 1 reads a row, transaction 2 modifies or deletes the line and commits. If transaction 1 wants to read this line again, it will either get the modified data or discover that it has been deleted, so the second read result of the transaction is different from the first read result, and therefore also called non-repeatable read.

Repeatable READ

Repeatable Read is a more restrictive isolation level than readcommitted. This level includes read COMMITTED, and also specifies that no other transaction can modify or delete the data that the current transaction has read until the current transaction commits. Concurrency is lower than read COMMITTED because shared locks on read data are held during the entire transaction, rather than being released at the end of each statement. For example, transaction 1 reads a row, transaction 2 wants to modify or delete the row and commit, but because transaction 1 has not yet been committed, the data row has a transaction 1 lock, transaction 2 is unable to update the operation, so transaction 2 is blocked. If the transaction 1 wants to read this line again, it reads the result the same as the first read, so it is called repeatable read.

Repetitive reading and phantom reading

Repeated reading is to ensure that in one transaction, the data values read under the same query condition do not change, but there is no guarantee that the next time the same condition query, the result record number will not increase.

The illusion of reading is to solve this problem, he has locked the scope of the query, so you can no longer insert data into this range, this is what serializable isolation level does.

Relationship of isolation level to lock

At READ UNCOMMITTED level, reading operation does not add S lock;

At the Read committed level, the read operation requires an S lock, but the S lock is released after the statement is executed;

Under the REPEATABLE read level, the read operation requires an S lock, but does not release the S lock until the transaction commits, that is, it must wait for the transaction to complete before releasing the S lock.

At the serialize level, a range lock is added on the basis of the repeatable read level. Ensure that the results of two queries within a transaction are exactly the same, without the result of the first query being a subset of the results of the second query.

2. Overload, override, overwrite

overload (Heavy): In a C + + program, several functions that are semantically and functionally similar can be represented by the same name, but the parameters or return values are different (including the type, the order differs), which is the function overload.
(1) The same range (in the same class);
(2) The function has the same name;
(3) different parameters;
(4) The virtual keyword is optional.

Override (overwrite): Refers to a derived class function that overrides a base class function, characterized by:
(1) different ranges (in the derived and base classes, respectively);
(2) The function has the same name;
(3) the same parameters;
(4) The base class function must have the virtual keyword.

Overwrite (override): refers to a function of a derived class that masks a base class function with the same name as the following rule:
(1) If the function of the derived class has the same name as the function of the base class, but the parameters are different. At this point, the function of the base class is hidden, regardless of the virtual keyword (Note that it is not confused with overloading).

(2) If the function of the derived class has the same name as the function of the base class, and the parameters are the same, the base class function does not have the virtual keyword. At this point, the function of the base class is hidden (be careful not to confuse the overlay).

Baidu interview (Database isolation level, overload, override)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.