MariaDB 10.4.34 无法运行查询,但 MariaDB 10.4.12 可以运行查询?
MariaDB 10.4.12 可以运行查询这个>> 我的询问
SELECT *
FROM
(
SELECT DATE_FORMAT(DATE(CONVERT_TZ(GROUP_CONCAT(inDate),'+00:00',
'+07:00')),'%d/%m/%Y') AS inPlan, CONVERT_TZ(GROUP_CONCAT(inDate),
'+00:00','+07:00'
) AS timee,tx.vehicleID,licenseNo,vehicleCode,
VehicleGroupName,VehicleSubGroupName,wk.firstName,wk.lastName,
wk.mobile,tx.planNo,planName,ref_planNo,WaypointSource,
WaypointDestination
FROM
(
SELECT vi.vehicleID,vi.licenseNo,vi.vehicleCode,vi.VehicleGroupName,
vi.VehicleSubGroupName,pp.inDate,p.planNo,p.planName,
ref_planNo,pp.pointType,pp.WaypointSource,pp.WaypointDestination
FROM
(
SELECT vehicleId,vehicleCode,licenseNo,
IFNULL(MAX(IF(tvg.LangID=2, tvg.TextVehicleGroupName,
NULL)), MAX(IF(tvg.LangID=1, tvg.TextVehicleGroupName,
NULL))
) AS VehicleGroupName,
IFNULL(MAX(IF(tvs.LangID=2,
tvs.TextVehicleSubgroupName, NULL)), MAX(IF(tvs.LangID=1,
tvs.TextVehicleSubgroupName,
NULL))
) AS VehicleSubGroupName,
vi.VehicleGroupID,
vi.VehicleSubGroupID FROM vehicle_info AS vi,
textword_vehicle_group AS tvg,
8887,12683,15608,4669,5970,5971, 5969,
5967,5963,5964,5965,5966,5962,5968,12660,
12664,12653, 12656,12657,12654,12662,
12658,12652,12655,12661,12685, 12679,
12681,12682,12684,12668,...,34470,34473,
11395,34479,
11394,34489,34488,35062,35022,35060,35066,
35069,35068, 35067) AND vi.companyid = 151 AND vi.CompanyID = tvg.CompanyID AND vi.VehicleGroupID = tvg.VehicleGroupID AND vi.CompanyID = tvs.CompanyID textword_vehicle_subgroup AS tvs WHERE vehicleid IN(7704,
AND vi.VehicleSubgroupID = tvs.VehicleSubgroupID AND vi.VehicleGroupID = tvs.VehicleGroupID GROUP BY vehicleid
) vi,
(
SELECT p.planNo,p.planName,p.statusDescription,p.status,p.ref_planNo
FROM plan p
WHERE companyid = 151
AND p.status IN (1,2,3,4,23,26)
) p ,
(
SELECT planno, MAX(IF(pointtype=2,wayname, NULL)) AS WaypointSource,
MAX(IF(pointtype=3,wayname, NULL)) AS WaypointDestination,
vehicleID, MIN(inDate) AS inDate, MIN(pointType) AS pointType,
waypointID
FROM
(
SELECT main.*
from
(
SELECT pp.planNo,pp.vehicleID,pp.waypointID,pp.pointType,pp.inDate,
wayname
FROM plan_point pp,
(
SELECT waypointID,
IFNULL(MAX(IF(tw.LangID=2,
tw.TextWaypointName,
NULL)),
MAX(IF(tw.LangID=1,
tw.TextWaypointName,
NULL))) AS wayname FROM textword_waypoint AS tw GROUP BY WaypointID
) AS tw WHERE pp.companyID = 151 AND tw.waypointid = pp.waypointID AND CONVERT_TZ(indate,
'+00:00',
'+07:00') BETWEEN STR_TO_DATE('01/09/2024 00:00',
'%d/%m/%Y %T') AND STR_TO_DATE('24/09/2024 23:59',
'%d/%m/%Y %T'
) GROUP BY planno,
vehicleid,pointtype,
indate) as main , ( SELECT pp.planNo ,
pp.vehicleID ,pp.waypointID ,
pp.pointType ,
max(pp.inDate),min(pp.inDate)) as inDate FROM plan_point pp WHERE pp.companyID = 151 AND CONVERT_TZ(indate,
'+00:00','+07:00') BETWEEN STR_TO_DATE('01/09/2024 00:00',
if(pp.pointType = 3, '%d/%m/%Y %T') AND STR_TO_DATE('24/09/2024 23:59',
'%d/%m/%Y %T'
) GROUP BY planno,
vehicleid,pointtype
) as selected where selected.planNo = main.planNo and selected.vehicleID = main.vehicleID and selected.pointType = main.pointType
and selected.inDate = main.inDate
GROUP BY planno,vehicleid,pointtype,indate
) AS aa
WHERE CONVERT_TZ(indate,'+00:00','+07:00') BETWEEN STR_TO_DATE('01/09/2024 00:00',
'%d/%m/%Y %T') AND STR_TO_DATE('24/09/2024 23:59','%d/%m/%Y %T'
)
AND vehicleid IN(7704,8887,12683,15608,4669,5970,5971,
5969,5967,5963,5964,5965,5966,5962,5968,12660,12664,12653,
12656,12657,12654,12662,12658,12652,12655,12661,12685,
12679,12681,12682,12684,12668,...34470,34473,11395,34479,
11394,34489,34488,35062,35022,35060,35066,35069,35068,
35067
)
GROUP BY planno
) pp
WHERE vi.vehicleID = pp.vehicleID
AND pp.planNo = p.planNo
AND pp.vehicleid IN (7704,8887,12683,15608,4669,5970,5971,
5969,5967,5963,5964,5965,5966,5962,5968,12660,12664,12653,
12656,,...,35021,35065,35036,35054,3956,4633,4634,4635,
4636,4637,3750,4641,4642,4643,3742,4644,35027,34480,34471,
34474,35023,34475,34476,34472,34478,34477,34469,34481,
34482,34470,34473,11395,34479,11394,34489,34488,35062,
35022,35060,35066,35069,35068,35067
)
GROUP BY vi.vehicleID,vi.licenseNo,vi.VehicleGroupName,pp.inDate,
p.planNo,p.planName,pp.pointType,pp.waypointID
) tx
LEFT JOIN
(
SELECT w.firstName,w.lastName,w.mobile,vw.vehicleID,vw.startDate,
vw.stopDate,vw.planNo
FROM worker w, vehicle_worker vw
WHERE vw.workerID = w.workerID
AND vw.planNo IS NOT NULL
AND w.companyID = 151
) wk ON wk.vehicleID = tx.vehicleID
AND (tx.inDate BETWEEN wk.startDate AND wk.stopDate)
AND wk.planNo = tx.planNo
GROUP BY vehicleID,licenseNo,planNo
ORDER BY inPlan ASC,licenseNo ASC
) AS aa
WHERE timee BETWEEN STR_TO_DATE('01/09/2024 00:00','%d/%m/%Y %T') AND STR_TO_DATE('24/09/2024 23:59',
'%d/%m/%Y %T'
)
ORDER BY vehicleGroupName,vehicleSubGroupName,vehicleId,
timee,planno;
ิ但是我将 Mariadb 升级到了 10.4.34 版本。并且查询无法在 Mariadb 10.4.34 上运行。 仅供参考 查询在 Mariadb 版本 10.4.12 上运行,只需几秒钟即可完成。但是查询相同的内容在 Mariadb 10.4.34 上运行很长时间并且不起作用,因为服务器认为它花费的时间太长,因此它终止了进程。 我希望知道如何解决这个问题的人告诉我原因。
设置group_concat_max_len = 1000000; join_buffer_size 1M;
其中一些可能会加速这个可怕的查询:
p: INDEX(status, planNo, planName, statusDescription, ref_planNo)
pp: INDEX(companyID, waypointID)
tw: INDEX(waypointid, LangID, TextWaypointName)
pp: INDEX(companyID, pointType)
selected: INDEX(planNo, vehicleID, pointType, inDate)
main: INDEX(planNo, vehicleID, pointType, inDate)
vi: INDEX(VehicleSubgroupID, VehicleGroupID, vehicleID)
pp: INDEX(vehicleID, planNo, vehicleid)
p: INDEX(planNo, planName, statusDescription, status, ref_planNo)
tvs: INDEX(VehicleSubgroupID, VehicleGroupID, LangID, TextVehicleSubgroupName, CompanyID)
w: INDEX(workerID, companyID, firstName, lastName, mobile)
vw: INDEX(workerID, planNo, vehicleID, startDate, stopDate)
tx: INDEX(vehicleID, planNo, inDate)
wk: INDEX(vehicleID)