Concept: If the CPU usage reaches 100% during stress testing for an SQL statement, this statement must be faulty. In the minds of most programmers, I always think that database indexing can improve database performance by using indexes in queries. In fact, this point of view has some limitations. If you do not make good use of the database indexes you have already created
Concept: If the CPU usage reaches 100% during stress testing for an SQL statement, this statement must be faulty. In the minds of most programmers, I always think that database indexing can improve database performance by using indexes in queries. In fact, this point of view has some limitations. If you do not make good use of the database indexes you have already created
Concept: If the CPU usage reaches 100% during stress testing for an SQL statement, this statement must be faulty.
In the minds of most programmers, I always think that database indexing can improve database performance by using indexes in queries. In fact, this point of view has some limitations. If you do not make good use of the database indexes you have already created, it sometimes puts more pressure on the database. Here is an example:
In the query of the logon location of the current personal information management system, there is such an SQL statement:
Select StudentInfoID, StudentNumber, StudentName, UnifyExamInfoID, NetSchoolID from StudentInfo
Where StudentCrtificateNumber = '2013' and rtrim (ltrim (StudentNumber) = 'd0462382001'
The purpose of this SQL statement is to check whether the examinee exists and verify the login effect. It is such a simple SQL statement. During stress testing, 10 users log on at the same time, the CPU usage of the database server (2 CPU, 4G memory, and IBM dedicated server) reaches 100%. This table also creates indexes for the StudentCrtificateNumber and StudentNumber fields. What is the problem? The reason is as follows:
(1) In the studentinfo table, an index LX_STUDENTINFO is created, which includes four fields in the order of studycenternumber, studentnumber, studentname, and studentcrtificatenumber.
(2) The programmer understands that this index includes these two fields, so the query should be fast. Actually not.
Note that the LX_STUDENTINFO index contains four index fields, and their sequence is studycenternumber, studentnumber, studentname, and studentcrtificatenumber. During database design, if the query uses the combination of the first field and the second field, the index is valid. If the query uses the combination of the first, second, and third fields, the index is also valid; if the first, third, or fourth combination is used, the index is invalid and the equivalent effect is still queried in the database without an index. That is to say, the fields in the created index cannot be used separately during query.
In addition, the order of fields involved in the index also affects the query performance. If an index contains both A1 and A2 fields, you must strictly design the query according to the order of the two fields in the index. For example, select * from a where A1 = 'A' and A2 = 'B '. If the programmer writes select * from awhere A2 = 'B' and A1 = 'A', the normal use of the program will not be affected, but it will increase the pressure on the database, the query efficiency is also reduced.
According to this idea, we re-adjusted the index of this table, and added a new index in this table, which only contains these two fields and sorted by StudentCrtificateNumber and StudentNumber in sequence. After a stress test of 300 simultaneous logon, the CPU usage only accounts for 2-3%, which proves that the adjustment result is valid.