From 95e4791586579d2bd0cd51434ee9bdf537ec6a98 Mon Sep 17 00:00:00 2001 From: Andrejs Verza Date: Thu, 6 Aug 2020 11:34:48 +0300 Subject: [PATCH] fixed slow SQL query when filtering items with latest data available --- ui/include/classes/api/managers/CHistoryManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/include/classes/api/managers/CHistoryManager.php b/ui/include/classes/api/managers/CHistoryManager.php index 8cbfb141d0..a16a6f3725 100644 --- a/ui/include/classes/api/managers/CHistoryManager.php +++ b/ui/include/classes/api/managers/CHistoryManager.php @@ -74,8 +74,8 @@ class CHistoryManager { 'SELECT itemid'. ' FROM '.self::getTableName($type). ' WHERE '.dbConditionInt('itemid', $type_itemids). - ' GROUP BY itemid'. - ($period ? ' HAVING MAX(clock)>'.$period : '') + ($period ? ' AND clock>'.$period : ''). + ' GROUP BY itemid' ), 'itemid'); $results += array_intersect_key($items, array_flip($type_results)); -- 2.21.0.windows.1