我有以下查询运行很长时间> 30分钟,我想知道是否有一些方法可以改善性能。
脚本通过Python(3.X)
执行加入的目标是在表格中填写US_vehicles的车辆详情。
表格设计说明
已经采取的措施:
表格信息:
INSERT INTO mergenhtsaed
(COMMENT, finalusid,
edmundsids, addvin,
length, height,
widthnomirror, bedlength,
bedlengthstd, doors,
torqueprimary, torqueprimaryrpm,
horsepowerrpmprimary, transtypestd,
transspeed, transtypestddetail,
drivenwheels, cafecarlineclass,
wheelbase, fronttrack,
reartrack, primaryfuelstd,
horsepowerprimary, hybrid,
flexfuel, bodystyle)
SELECT "1:",
FU.id,
Group_concat(DISTINCT UV.id),
Group_concat(DISTINCT squishvins),
Round(Avg(UV.overall_length), 1),
Round(Avg(UV.overall_height), 1),
Round(Avg(UV.overall_width_without_mirrors), 1),
Round(Avg(bedlength), 1),
Round(Avg(bedsizestdft), 1),
Group_concat(DISTINCT UV.numofdoors),
Round(Avg(UV.engine_torque)),
Round(Avg(UV.engine_rpm_torque)),
Round(Avg(UV.engine_rpm_horsepower)),
UV.transtypestd,
UV.transspeed,
UV.transtypestddetail,
UV.drivenwheelsstd,
Group_concat(DISTINCT uv .` categories_epaclass ` ),
Round(Avg(UV.wheelbase), 1),
Round(Avg(UV.front_track), 1),
Round(Avg(UV.rear_track), 1),
Group_concat(DISTINCT UV.primaryfuelstd),
Round(Avg(UV.engine_horsepower)),
Group_concat(DISTINCT UV.hybrid),
Group_concat(DISTINCT UV.flexfuel),
Group_concat(DISTINCT UV.bodystyle)
FROM finalus FU
inner join us_vehicles UV
ON UV.years_year = FU.modelyear
AND fu .` vin ` IN ( UV.vin1, UV.vin2, UV.vin3, UV.vin4,
UV.vin5, UV.vin6, UV.vin7, UV.vin8,
UV.vin9, UV.vin10, UV.vin11, UV.vin12,
UV.vin13, UV.vin14, UV.vin15, UV.vin16,
UV.vin17, UV.vin18, UV.vin19, UV.vin20,
UV.vin21, UV.vin22, UV.vin23, UV.vin24,
UV.vin25, UV.vin26, UV.vin27, UV.vin28,
UV.vin29, UV.vin30, UV.vin31, UV.vin32,
UV.vin33, UV.vin34 )
WHERE FU.modelyear < 2012
AND FU.edmundsid IS NULL
AND FU.dataoneid IS NULL
GROUP BY FU.id
HAVING Count(DISTINCT UV.id) = 1
解释查询计划
Selectid|order|from|detail
"0"|"0"|"0"|"SEARCH TABLE FinalUS AS FU USING INDEX Idx3 (EdmundsId=?)"
"0"|"1"|"1"|"SCAN TABLE US_Vehicles AS UV"