After writing code for several years, the interview still fails? Have you read these questions? Lay a good foundation for the interview!

2020 latest Java collection of common interview questions + detailed answers (15)

Continue to update Java related materials. Recently, I have spent a few days consulting the latest interview news of the big bosses, trying to collect more comprehensive interview information. If you want to see the first few collections, you can go to my homepage to find them.

Some of the answers are summarized by myself, and some are collected on the Internet. Don't panic after watching these interviews! If you have more experience, you can share it in the comments. If you have any mistakes, you are welcome to point out. Please feel free to enlighten me, thank you

149. How is the mysql index implemented?

An index is a data structure that satisfies a certain search algorithm, and these data structures point to the data in a certain way, so as to achieve efficient data search.

 

Specifically, the indexes in MySQL are implemented differently by different data engines, but the indexes of the current mainstream database engines are all implemented by B+ trees. The search efficiency of B+ trees can reach the performance of the dichotomy. After finding the data area, The complete data structure is found, and the performance of all indexes is better.

150. How to verify whether the mysql index meets the requirements?

Use explain to view how SQL executes query statements, so as to analyze whether your index meets the requirements.

 

explain 语法:explain select * from table where type=1。

151. Talk about the transaction isolation of the database?

MySQL transaction isolation is added in the MySQL.ini configuration file, add at the end of the file: transaction-isolation = REPEATABLE-READ

 

Available configuration values: READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE.

 

  • READ-UNCOMMITTED: uncommitted read, the lowest isolation level, before the transaction is committed, it can be read by other transactions (phantom reads, dirty reads, and non-repeatable reads will occur).

  • READ-COMMITTED: Commit read, a transaction can only be read by other transactions after it is committed (it will cause phantom reads and non-repeatable reads).

  • REPEATABLE-READ: Repeatable reading, the default level, to ensure that when the same data is read multiple times, its value is consistent with the content at the beginning of the transaction. It is forbidden to read the uncommitted data of other transactions (will cause phantom reads) .

  • SERIALIZABLE: Serialization, the most costly and most reliable isolation level, this isolation level can prevent dirty reads, non-repeatable reads, and phantom reads.

 

Dirty read: indicates that a transaction can read data that has not yet been committed in another transaction. For example, a transaction tries to insert record A, and the transaction has not yet committed, and then another transaction tries to read record A.

 

Non-repeatable reading: refers to reading the same data multiple times in a transaction.

 

Phantom reading: Refers to the different result sets returned by multiple queries within the same transaction. For example, the same transaction A has n records in the first query, but there are n+1 records in the second query under the same conditions, which seems to be an illusion. The reason for the phantom read is that another transaction adds, deletes, or modifies the data in the first transaction result set. If the data content of the same record is modified, the records of all data rows become more or less.

 

It will be more effective if you look at the self-check of the question and then the detailed answer.

152. Tell me about the commonly used engines of mysql?

InnoDB engine: InnoDB engine provides support for database acid transactions, and also provides row-level locks and foreign key constraints. Its design goal is to handle large data capacity database systems. When MySQL is running, InnoDB will create a buffer pool in memory for buffering data and indexes. However, the engine does not support full-text search, and it is relatively slow to start. It does not save the number of rows in the table, so when the select count(*) from table instruction is executed, the entire table needs to be scanned. Because the lock granularity is small, the write operation will not lock the entire table, so it will improve efficiency when used in scenarios with high concurrency.

 

MyIASM engine: MySQL's default engine, but does not provide transaction support, nor does it support row-level locks and foreign keys. Therefore, when performing insert and update statements, that is, when performing write operations, the table needs to be locked, which will reduce efficiency. However, unlike InnoDB, the MyIASM engine saves the number of rows in the table, so when the select count(*) from table statement is executed, the saved value can be directly read without scanning the entire table. Therefore, if the table has far more read operations than write operations and does not require transaction support, you can use MyIASM as the first choice for the database engine.

153. Tell me about the row lock and table lock of mysql?

MyISAM only supports table locks, InnoDB supports table locks and row locks, and the default is row locks.

 

  • Table-level locks: low overhead, fast locking, and no deadlocks. Large locking granularity, the highest probability of lock conflicts, and the lowest concurrency.

  • Row-level locks: high overhead, slow locking, and deadlocks. The lock strength is small, the probability of lock conflicts is small, and the concurrency is the highest.

154. Talk about optimistic locking and pessimistic locking?

  • Optimistic lock: Every time you get the data, you think that others will not modify it, so it will not be locked, but when you submit the update, it will be judged whether others have updated the data during this period.

  • Pessimistic lock: Every time you get the data, you think that others will modify it, so you will lock it every time you get the data, so that other people want to get the data will be blocked until the lock is released.

 

The optimistic lock of the database needs to be implemented by yourself. Add a version field to the table, and add 1 to the successful value of each modification, so that when you modify each time you first compare whether your own version is consistent with the current version of the database, if not, don’t Modify, so that optimistic locking is realized.

155. What are the methods for mysql troubleshooting?

  • Use the show processlist command to view all current connection information.

  • Use the explain command to query the SQL statement execution plan.

  • Open the slow query log to view the SQL of the slow query.

156. How to optimize the performance of mysql?

  • Create an index for the search field.

  • Avoid using select * and list the fields that need to be queried.

  • Split table vertically.

  • Choose the right storage engine.

    At last

    The content of the interview questions is over here, there will be more updates in the follow-up, I hope it will be helpful to everyone.

    Finally, I want to say something to you. I have worked for so many years and have interviewed some people for others. Whether it is from the perspective of the interviewer or the leader, in addition to interview skills and experience, great technology and project experience are also their trump cards and confidence. Core technology sharing of first-tier manufacturers

     It took me a long time to sort out some learning materials. What I posted above is the tip of the iceberg in the materials. I hope I can help you! Click to learn the secret code together: csdn

                             

      I will share more pure dry goods articles in the follow-up, and hope to really help you. Your support is my biggest motivation! Welcome to follow and like!

                                                           

Guess you like

Origin blog.csdn.net/weixin_50333534/article/details/108999416