JAVA senior development engineer interview questions 2023

Senior Development Engineer Interview Questions-Xuan

1. InnoDB row overflow

The so-called row overflow can actually be understood as page overflow. The reason why row overflow occurs is because of the variable length fields in the stored data: for example, varChar and Text will generate a byte that overflows the page overflow department when it exceeds the 16KB specified by InnoDB. The data will be stored in the overflow page. The original leaf node will have a size of about 2KB to store an address value pointing to the overflow page so that the data can be perfectly connected.

2. Mysql write failure

First of all, let me mention that one page of data in Mysql is 16KB, but the system page is only 4KB. The so-called write failure is because during the process of Mysql writing to the system disk, the 16KB data needs to be divided into 4 parts and written in 4 parts. If the database goes down before writing is completed, the write will fail. "Solution": DoubleWrite Buffer: InnoDB implements DoubleWrite Buffer so that the data that needs to be written reaches the doublewrite buffer first. If the database goes down during this period, it will be restarted next time. When executing, it will be executed from the double write buffer first to ensure that no write failure will occur.

3. Advantages and disadvantages of Hash index

InnoDB uses the B+Tree index by default, but it also provides a special Hash index. It will monitor the index table. If it monitors that an index is frequently used, it will be marked as hot data. InnoDB will create an adaptive Hash index in the memory. If you query this data next time, InnoDB will calculate the hash code value through the Hash algorithm. Because it is stored in the form of KeyValue, you can directly query all the required data at once, avoiding multiple node scans through the B+Tree index. Improved Query efficiency

"Advantages" Because the index itself needs to store Hash values, the index structure is very compact. It is also very efficient to perform equivalent queries instead of range queries.

"Disadvantages" Only supports equivalent queries but not range queries. Because the Hash index is not stored by creation time, it is not sorted.

4. Slow query optimization

By turning on show_query_log (but turning it on will consume Mysql performance)

show_query_log_file (slow query log address)

log_query_time (the slow query specified time threshold exceeds this time before the log is recorded)

The information in the log includes: execution time, user information, query duration, waiting time for lock, number of query result rows, number of scanned rows, SQL records

"Causes of slow performance": long waiting time and long execution time

"Optimization Ideas"

Filter out slow query SQL with high concurrency or high usage for optimization

Locate the bottleneck of the optimization object (IO optimization, CPU optimization, network bandwidth optimization)

Index exploration through the Explain process

Reduce database IO operations in a loop

Reduce useless column queries and where conditions

Avoid JOIN queries and subqueries

5. Paging query optimization

Ordinary paging query may be

Select * from 表 limit 0,100

When using index

Select * from 表 where id >1000 limit 100

Using subqueries

Select * from 表 where(Select id from 表 where id > 100) limit 100

Common values ​​used in index queries

System、const、eq_ref、ref、range、index、ALL

System: Get the data directly without going through database IO

Const: Take out all the query data at once, mainly clustered indexes

Eq_ref: Find the unique index, return at most one piece of data

Ref: Find non-unique indexes and return multiple pieces of data

Range: Query part of an index, only retrieve range queries

Index: Search all index trees because the index file is smaller than the data file

ALL: Full table scan without index

Guess you like

Origin blog.csdn.net/GSl0408/article/details/130647595