Database optimization subtotal optimizes database tables related to XX businesses on Monday night. Cause: there are 4 tables in total, with a small data size, a minimum of 0.4 million records, a maximum of 3 million, and a size of no more than 300 MB. However, due to historical reasons, the table has not been indexed, and the corresponding service uses a variety of SQL statements, which are difficult to modify and easy to correct. Many customers throughout the country are involved, most of which are full table scans, the response time is several seconds, but most customers can handle it. Objective: To improve the efficiency of full table scanning for such tables that cannot improve the response speed by creating indexes and reducing the data volume, that is, water level line. Solution: After several improvements, the itinerary is available: Part 1: 1,
CREATE TABLE XXX_20130910 AS SELECT * FROM XXX;
Use the original table to create an intermediate table. 2,
TRUNCATE XXX;
Truncate original table. 3,
INSERT INTO XXX SELECT * FROM XXX_20130910 WHERE
7 days; insert the data for 7 days into the original table. Start the corresponding service at this time. This process ensures that the production table can be restored in the shortest time. Part 2: Create a History Table: 1,
CREATE TABLE XXX_HISTORY AS SELECT * FROM XXX_20130910 WHERE 1<>1;
Create an empty history table using the intermediate table. 2. Create a night dimension to import data from the production table seven days ago to the history table every day. After the overall operation is completed, the table used for production maintains the data volume for seven days. Even if the business volume increases, the waterline will not increase too much and remain at a certain height. At the same time, by importing the historical data of the production table into the historical table, both historical data backup and data volume of the production table are ensured. Online: The first part includes the total inspection time of 20 minutes. The second part starts after the test is confirmed with the user, which takes about 10 minutes. Effect: the results after the release on the same day are still acceptable. The response time of most applications is reduced from the second level to the xx millisecond level, which is to be viewed within a period of time. Conclusion: The whole process has been modified and summarized several times, and the step manual has been sorted out for the launch day, indicating the operations of each step and the points of attention, so the operation is quite smooth on the day, it is time-consuming to stop applications and test applications with multiple customers. Different customers have different degrees of cooperation, but they are more cooperative. For database table optimization, the above operations have actually been streamlined to the simplest statement. I think the optimization operation is not so complicated, but the most important thing is simple, effective, and secure, what's more, there is no user-driven optimization. If you do a good job, you may not be able to say anything about you. If you do something wrong, someone will call it. The loss is worth the candle. Therefore, different optimization operations may have different methods, however, the core should be "simple, effective, and secure", so as to achieve the best effect. Personal Opinion, please be prepared!