Interview questions:
Which databases have you used, database optimization operations
(Recommended tutorial: java teaching video)
Answer:
1. Configure mysql performance optimization parameters according to the service level
;
2. Enhance the performance of mysql from the system level: Optimize the data table structure
① Decompose a table with many fields into multiple tables
For tables with many fields, if some fields are used very rarely, you can separate these fields Create a new table. Because when a table has a large amount of data, the query speed will slow down due to the presence of infrequently used fields.
(Recommendations for more related interview questions: java interview questions and answers)
② Add intermediate tables
For tables that often require joint queries, Intermediate tables can be created to improve query efficiency. By establishing an intermediate table, insert data that requires frequent joint queries into the intermediate table, and then change the original joint query to a query on the intermediate table to improve query efficiency.
3. Enhance performance from the database level
Optimize SQL statements and use field indexes rationally.
4. Enhance performance from the code level: use cache and NoSQL database storage, such as MongoDB/Memcached/Redis to alleviate the pressure of database queries under high concurrency.
5. Reduce the number of database operations and try to use database access-driven batch processing methods.
6. Migrate and backup infrequently used data to avoid searching in massive data every time.
7. Improve the hardware configuration of the database server or build a database cluster.
8. Programming methods to prevent SQL injection: use JDBC PreparedStatement to insert or query bit by bit; regular expression filtering (illegal string filtering);
Related recommendations: java introductory tutorial
The above is the detailed content of Database performance optimization for java interview. For more information, please follow other related articles on the PHP Chinese website!