Home > database >  Use Mybatis multiple statements batch update speed slow is what reason, Mysql using InnoDb
Use Mybatis multiple statements batch update speed slow is what reason, Mysql using InnoDb

Time:10-26

Scenario is: need to students admitted to volunteer information updates to the database, a total of about 7000 records, in batches, each operation 200, because each student admissions volunteer is not necessarily the same, so I use cycle execute multiple SQL, but found that slow, druid, took a total of 6 minutes, if you are using MyIsam was completed a few seconds,

Inside the mapper is written like this:

 
The UPDATE t_student
SET # accepted_major_id={student. AcceptedMajorId}, accepted_type=# {student. AcceptedType}
WHERE student_id=# {student. StudentId}


CodePudding user response:

Has been solved, because there is no open transactions, every sentence update default is a transaction, the transaction is much slower, open transactions to update faster, 1.9 seconds,
Can also be done with a case statement with a SQL
 
The UPDATE t_student
The WHEN student_id=# {item. StudentId} THEN # {item. AcceptedMajorId}


The WHEN student_id=# {item. StudentId} THEN # {item. AcceptedType}



WHERE student_id IN
# {item. StudentId}


  • Related