Home > database >  MySql statement optimization
MySql statement optimization

Time:11-05

I ask, how to optimize the following SQL statements, the current execution speed is very slow, led directly to the timeout throw exceptions,
MySQL 8.0

The SELECT, Anderson d a. atteryCode, a.C reateTime, arjun oduleCode, a. indTime,
(SELECT CreateTime FROM tb_bend1info where BatteryCode=a. atteryCode order by id desc limit 1) as bend1,
(SELECT SealTempSet1 FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal1,
(SELECT SealTempSet2 FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal2,
(SELECT SealTimeSet FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal3,
(SELECT CreateTime FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal4,
(SELECT CreateTime FROM tb_bend2info where BatteryCode=a. atteryCode order by id desc limit 1) as bend2,
(SELECT CreateTime FROM tb_stickinfo where BatteryCode=a. atteryCode order by id desc limit 1) as stick,
(SELECT Voltage FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv1,
(SELECT to hold the FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv2,
(SELECT TestResult FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv3,
(SELECT CreateTime FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv4,
(SELECT TrimPoint1 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim1,
(SELECT TrimPoint2 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim2,
(SELECT TrimPoint3 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim3,
(SELECT TrimPoint4 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim4,
(SELECT TrimLengthA FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as TrimLengthA,
(SELECT TrimLengthB FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as TrimLengthB,
(SELECT CreateTime FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim5,
(SELECT CreateTime FROM tb_plasmaparam where BatteryCode=a. atteryCode order by id desc limit 1) as plasma
The FROM (SELECT * FROM TB_BatteryInfo where BatteryCode & lt;> ") where a a. atteryCode like '% ABC %' "and a.C reateTime>=@ StartTime and a.C reateTime<=@ EndTime

CodePudding user response:

All the tables, BatteryCode fields and indexes,
The SELECT, Anderson d a. atteryCode, a.C reateTime, arjun oduleCode, a. indTime,
(SELECT CreateTime FROM tb_bend1info where BatteryCode=a. atteryCode order by id desc limit 1) as bend1,
(SELECT SealTempSet1 FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal1,
(SELECT SealTempSet2 FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal2,
(SELECT SealTimeSet FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal3,
(SELECT CreateTime FROM tb_sealtest where BatteryCode=a. atteryCode order by id desc limit 1) as seal4,
(SELECT CreateTime FROM tb_bend2info where BatteryCode=a. atteryCode order by id desc limit 1) as bend2,
(SELECT CreateTime FROM tb_stickinfo where BatteryCode=a. atteryCode order by id desc limit 1) as stick,
(SELECT Voltage FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv1,
(SELECT to hold the FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv2,
(SELECT TestResult FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv3,
(SELECT CreateTime FROM tb_ocvtest where BatteryCode=a. atteryCode order by id desc limit 1) as ocv4,
(SELECT TrimPoint1 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim1,
(SELECT TrimPoint2 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim2,
(SELECT TrimPoint3 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim3,
(SELECT TrimPoint4 FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim4,
(SELECT TrimLengthA FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as TrimLengthA,
(SELECT TrimLengthB FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as TrimLengthB,
(SELECT CreateTime FROM tb_triminfo where BatteryCode=a. atteryCode order by id desc limit 1) as trim5,
(SELECT CreateTime FROM tb_plasmaparam where BatteryCode=a. atteryCode order by id desc limit 1) as plasma
The FROM TB_BatteryInfo where a a. atteryCode like '% ABC %' "and a.C reateTime between @ StartTime and @ EndTime

CodePudding user response:

nullnull
  • Related