Skip to content

Commit a18c300

Browse files
yhabteablippserd
andcommitted
LEFT JOIN hosts in the history view
Otherwise, MySQL won't utilize the event_time index. Co-authored-by: Eric Lippmann <eric.lippmann@icinga.com>
1 parent 29ca493 commit a18c300

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

application/controllers/HistoryController.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ public function indexAction()
7878

7979
$history->filter(Filter::lessThanOrEqual('event_time', $before));
8080
$this->filter($history, $filter);
81+
82+
$history->getWith()['history.host']->setJoinType('LEFT');
8183
$history->getSelectBase()
82-
// Make sure we'll fetch service history entries only for services which still exist
83-
->where(['history.service_id IS NULL', 'history_service.id IS NOT NULL'], Sql::ANY);
84+
// Because of LEFT JOINs, make sure we'll fetch history entries only for items which still exist:
85+
->where(['history_host.id IS NOT NULL', 'history_service.id IS NOT NULL'], Sql::ANY);
8486

8587
yield $this->export($history);
8688

0 commit comments

Comments
 (0)