diff --git a/include/zbxcacheconfig.h b/include/zbxcacheconfig.h
index 9767f126b41..adbe226a01e 100644
--- a/include/zbxcacheconfig.h
+++ b/include/zbxcacheconfig.h
@@ -1001,6 +1001,7 @@ typedef struct
 	zbx_uint64_t			eventid;		/* [IN] eventid */
 	zbx_uint64_t			r_eventid;		/* [-] recovery eventid */
 	zbx_uint64_t			triggerid;		/* [-] triggerid */
+	zbx_vector_uint64_t		hostids;		/* [-] associated hostids */
 	zbx_vector_uint64_t		functionids;		/* [IN] associated functionids */
 	zbx_vector_tags_t		tags;			/* [IN] event tags */
 	zbx_vector_uint64_pair_t	maintenances;		/* [OUT] actual maintenance data for the event in */
diff --git a/src/libs/zbxcacheconfig/dbconfig_maintenance.c b/src/libs/zbxcacheconfig/dbconfig_maintenance.c
index 9f59f7c23c4..5a10f1fc474 100644
--- a/src/libs/zbxcacheconfig/dbconfig_maintenance.c
+++ b/src/libs/zbxcacheconfig/dbconfig_maintenance.c
@@ -938,17 +938,11 @@ static void	dc_assign_maintenance_to_host(zbx_hashset_t *host_maintenances, zbx_
 static void	dc_assign_event_maintenance_to_host(zbx_hashset_t *host_event_maintenances,
 		zbx_dc_maintenance_t *maintenance, zbx_uint64_t hostid)
 {
-	zbx_host_event_maintenance_t	*host_event_maintenance, host_event_maintenance_local;
+	zbx_host_event_maintenance_t	*host_event_maintenance;
 
 	if (NULL == (host_event_maintenance = (zbx_host_event_maintenance_t *)zbx_hashset_search(
 			host_event_maintenances, &hostid)))
 	{
-		host_event_maintenance_local.hostid = hostid;
-		zbx_vector_ptr_create(&host_event_maintenance_local.maintenances);
-		zbx_vector_ptr_append(&host_event_maintenance_local.maintenances, maintenance);
-
-		zbx_hashset_insert(host_event_maintenances, &host_event_maintenance_local,
-				sizeof(host_event_maintenance_local));
 		return;
 	}
 
@@ -962,8 +956,8 @@ typedef void	(*assign_maintenance_to_host_f)(zbx_hashset_t *host_maintenances,
  *                                                                            *
  * Purpose: get hosts and their maintenances                                  *
  *                                                                            *
- * Parameters: maintenanceids    - [IN] the maintenance ids                   *
- *             host_maintenances - [OUT] the maintenances running on hosts    *
+ * Parameters: maintenanceids    - [IN] maintenance ids                       *
+ *             host_maintenances - [OUT] maintenances running on hosts        *
  *             cb                - [IN] callback function                     *
  *                                                                            *
  ******************************************************************************/
@@ -1410,14 +1404,11 @@ int	zbx_dc_get_event_maintenances(zbx_vector_ptr_t *event_queries, const zbx_vec
 	zbx_event_suppress_query_t	*query;
 	ZBX_DC_ITEM			*item;
 	ZBX_DC_FUNCTION			*function;
-	zbx_vector_uint64_t		hostids;
 	zbx_hashset_iter_t		iter;
 	zbx_host_event_maintenance_t	*host_event_maintenance;
 
 	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
 
-	zbx_vector_uint64_create(&hostids);
-
 	zbx_hashset_create_ext(&host_event_maintenances, maintenanceids->values_num, ZBX_DEFAULT_UINT64_HASH_FUNC,
 			ZBX_DEFAULT_UINT64_COMPARE_FUNC, (zbx_clean_func_t)host_event_maintenance_clean,
 			ZBX_DEFAULT_MEM_MALLOC_FUNC, ZBX_DEFAULT_MEM_REALLOC_FUNC, ZBX_DEFAULT_MEM_FREE_FUNC);
@@ -1432,18 +1423,7 @@ int	zbx_dc_get_event_maintenances(zbx_vector_ptr_t *event_queries, const zbx_vec
 
 	RDLOCK_CACHE;
 
-	dc_get_host_maintenances_by_ids(maintenanceids, &host_event_maintenances, dc_assign_event_maintenance_to_host);
-
-	if (0 == host_event_maintenances.num_data)
-		goto unlock;
-
-	zbx_hashset_iter_reset(&host_event_maintenances, &iter);
-
-	while (NULL != (host_event_maintenance = (zbx_host_event_maintenance_t *)zbx_hashset_iter_next(&iter)))
-	{
-		zbx_vector_ptr_sort(&host_event_maintenance->maintenances, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
-		zbx_vector_ptr_uniq(&host_event_maintenance->maintenances, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
-	}
+	zbx_prof_start("event_queries", ZBX_PROF_PROCESSING);
 
 	for (i = 0; i < event_queries->values_num; i++)
 	{
@@ -1498,21 +1478,74 @@ int	zbx_dc_get_event_maintenances(zbx_vector_ptr_t *event_queries, const zbx_vec
 				continue;
 
 			if (HOST_MAINTENANCE_STATUS_OFF == dc_host->maintenance_status)
-				goto skip;
+			{
+				zbx_vector_uint64_clear(&query->hostids);
+				break;
+			}
+
+			zbx_vector_uint64_append(&query->hostids, item->hostid);
+		}
+
+		if (0 == query->hostids.values_num)
+			continue;
+
+		zbx_vector_uint64_sort(&query->hostids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+		zbx_vector_uint64_uniq(&query->hostids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+
+		for (j = 0; j < query->hostids.values_num; j++)
+		{
+			zbx_host_event_maintenance_t	hem_local = {.hostid = query->hostids.values[j]};
 
-			zbx_vector_uint64_append(&hostids, item->hostid);
+			zbx_hashset_insert(&host_event_maintenances, &hem_local, sizeof(hem_local));
 		}
+	}
+
+	zbx_prof_end();
 
-		zbx_vector_uint64_sort(&hostids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
-		zbx_vector_uint64_uniq(&hostids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
+	zbx_prof_start("host_event_maintenances reserve", ZBX_PROF_PROCESSING);
+
+	zbx_hashset_iter_reset(&host_event_maintenances, &iter);
+	while (NULL != (host_event_maintenance = (zbx_host_event_maintenance_t *)zbx_hashset_iter_next(&iter)))
+	{
+		zbx_vector_ptr_create(&host_event_maintenance->maintenances);
+		zbx_vector_ptr_reserve(&host_event_maintenance->maintenances, (size_t)maintenanceids->values_num);
+	}
+
+	zbx_prof_end();
+
+	zbx_prof_start("dc_get_host_maintenances_by_ids", ZBX_PROF_PROCESSING);
+
+	dc_get_host_maintenances_by_ids(maintenanceids, &host_event_maintenances, dc_assign_event_maintenance_to_host);
+
+	zbx_prof_end();
+
+	if (0 == host_event_maintenances.num_data)
+		goto unlock;
+
+	zbx_prof_start("host_event_maintenance sort", ZBX_PROF_PROCESSING);
+
+	zbx_hashset_iter_reset(&host_event_maintenances, &iter);
+	while (NULL != (host_event_maintenance = (zbx_host_event_maintenance_t *)zbx_hashset_iter_next(&iter)))
+	{
+		zbx_vector_ptr_sort(&host_event_maintenance->maintenances, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
+		zbx_vector_ptr_uniq(&host_event_maintenance->maintenances, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
+	}
+
+	zbx_prof_end();
+
+	zbx_prof_start("find matching maintenances", ZBX_PROF_PROCESSING);
+
+	for (i = 0; i < event_queries->values_num; i++)
+	{
+		query = (zbx_event_suppress_query_t *)event_queries->values[i];
 
 		/* find matching maintenances */
-		for (j = 0; j < hostids.values_num; j++)
+		for (j = 0; j < query->hostids.values_num; j++)
 		{
 			const zbx_dc_maintenance_t	*maintenance;
 
 			if (NULL == (host_event_maintenance = zbx_hashset_search(&host_event_maintenances,
-					&hostids.values[j])))
+					&query->hostids.values[j])))
 			{
 				continue;
 			}
@@ -1542,13 +1575,12 @@ int	zbx_dc_get_event_maintenances(zbx_vector_ptr_t *event_queries, const zbx_vec
 				ret = SUCCEED;
 			}
 		}
-skip:
-		zbx_vector_uint64_clear(&hostids);
 	}
+
+	zbx_prof_end();
 unlock:
 	UNLOCK_CACHE;
 
-	zbx_vector_uint64_destroy(&hostids);
 	zbx_hashset_destroy(&host_event_maintenances);
 
 	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
@@ -1563,6 +1595,7 @@ unlock:
  ******************************************************************************/
 void	zbx_event_suppress_query_free(zbx_event_suppress_query_t *query)
 {
+	zbx_vector_uint64_destroy(&query->hostids);
 	zbx_vector_uint64_destroy(&query->functionids);
 	zbx_vector_uint64_pair_destroy(&query->maintenances);
 	zbx_vector_tags_clear_ext(&query->tags, zbx_free_tag);
diff --git a/src/zabbix_server/events.c b/src/zabbix_server/events.c
index ed7044a3e64..00ce0f6eaeb 100644
--- a/src/zabbix_server/events.c
+++ b/src/zabbix_server/events.c
@@ -2033,6 +2033,7 @@ static void	add_event_suppress_data(zbx_vector_ptr_t *event_refs, zbx_vector_uin
 		query = (zbx_event_suppress_query_t *)zbx_malloc(NULL, sizeof(zbx_event_suppress_query_t));
 		query->eventid = event->eventid;
 
+		zbx_vector_uint64_create(&query->hostids);
 		zbx_vector_uint64_create(&query->functionids);
 		zbx_db_trigger_get_all_functionids(&event->trigger, &query->functionids);
 
diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c
index 686e93bb202..f3c52c919a0 100644
--- a/src/zabbix_server/timer/timer.c
+++ b/src/zabbix_server/timer/timer.c
@@ -245,6 +245,7 @@ static void	event_queries_fetch(DB_RESULT result, zbx_vector_ptr_t *event_querie
 			query->eventid = eventid;
 			ZBX_STR2UINT64(query->triggerid, row[1]);
 			ZBX_DBROW2UINT64(query->r_eventid, row[2]);
+			zbx_vector_uint64_create(&query->hostids);
 			zbx_vector_uint64_create(&query->functionids);
 			zbx_vector_tags_create(&query->tags);
 			zbx_vector_uint64_pair_create(&query->maintenances);
