MySQL查询挂起

时间:2017-01-23 11:17:36

标签: mysql query-performance

我有一个mysql查询,但它只是挂起并且不会停止。我不确定查询在哪里破解。

SELECT
 TIMESTAMPDIFF(SECOND, '1970-01-01 00:00:00', f.Datestamp) AS Epoch,
 f.value AS `Usage`,
 q.Name AS Quantity,
 q.QuantityID,
 units,
 PrimeDataItem,
 dd.Description
FROM SourceChannels c
 JOIN UsageHhourly f ON c.ChanID = f.ChanID
 JOIN Quantities q ON c.QuantityID = q.QuantityID
 LEFT JOIN DigitalDescriptions dd ON ((c.DigitalDescriptionID = dd.DigitalDescriptionID)
 AND f.value = (CASE WHEN dd.Value REGEXP '^[0-9]' = 1 then dd.Value ELSE -1 END))
WHERE
 c.EquipmentID = 1496
 AND f.DateStamp >= '2016-12-28 00:00:00'
 AND f.DateStamp < '2017-01-04 00:00:00'
ORDER BY q.QuantityID, f.datestamp

1 个答案:

答案 0 :(得分:0)

这个问题没有提供更多的照明信息。尝试更改您的查询,如下例所示。

SELECT
 TIMESTAMPDIFF(SECOND, '1970-01-01 00:00:00', `f`.`Datestamp`) AS `Epoch`,
 `f`.`value` AS `Usage`,
 `q`.`Name` AS `Quantity`,
 `q`.`QuantityID`,
 `c`.`units`,
 `c`.`PrimeDataItem`,
 `dd`.`Description`
FROM `SourceChannels` `c`
 INNER JOIN `UsageHhourly` `f` ON `c`.`ChanID` = `f`.`ChanID`
 INNER JOIN `Quantities` `q` ON `c`.`QuantityID` = `q`.`QuantityID`
 LEFT JOIN `DigitalDescriptions` `dd` ON `c`.`DigitalDescriptionID` = `dd`.`DigitalDescriptionID`
WHERE
`f`.`value` = IF((dd.Value REGEXP '^[0-9]'),1,-1)
 AND `c`.`EquipmentID` = 1496
 AND `f`.`DateStamp` BETWEEN '2016-12-28 00:00:00' AND '2017-01-04 00:00:00'
 ORDER BY `q`.`QuantityID`, `f`.`datestamp`;