Skip to content

Commit eb468af

Browse files
authored
Merge pull request #397 from Icinga/introduce-more-indexes
Add more MySQL indexes
2 parents c1d826f + 611b68c commit eb468af

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

schema/mysql/schema.sql

+37-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ CREATE TABLE hostgroup (
8080

8181
zone_id binary(20) DEFAULT NULL COMMENT 'zone.id',
8282

83-
PRIMARY KEY (id)
83+
PRIMARY KEY (id),
84+
85+
INDEX idx_hostroup_name (name) COMMENT 'Host/service/host group list filtered by host group name'
8486
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
8587

8688
CREATE TABLE hostgroup_member (
@@ -162,7 +164,12 @@ CREATE TABLE host_state (
162164
next_update bigint unsigned NOT NULL,
163165

164166
PRIMARY KEY (id),
165-
UNIQUE INDEX idx_host_state_host_id (host_id)
167+
168+
UNIQUE INDEX idx_host_state_host_id (host_id),
169+
INDEX idx_host_state_is_problem (is_problem, severity) COMMENT 'Host list filtered by is_problem ordered by severity',
170+
INDEX idx_host_state_severity (severity) COMMENT 'Host list filtered/ordered by severity',
171+
INDEX idx_host_state_soft_state (soft_state, last_state_change) COMMENT 'Host list filtered/ordered by soft_state; recently recovered filter',
172+
INDEX idx_host_state_last_state_change (last_state_change) COMMENT 'Host list filtered/ordered by last_state_change'
166173
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
167174

168175
CREATE TABLE service (
@@ -236,7 +243,9 @@ CREATE TABLE servicegroup (
236243

237244
zone_id binary(20) DEFAULT NULL COMMENT 'zone.id',
238245

239-
PRIMARY KEY (id)
246+
PRIMARY KEY (id),
247+
248+
INDEX idx_servicegroup_name (name) COMMENT 'Host/service/service group list filtered by service group name'
240249
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
241250

242251
CREATE TABLE servicegroup_member (
@@ -321,7 +330,12 @@ CREATE TABLE service_state (
321330
next_update bigint unsigned NOT NULL,
322331

323332
PRIMARY KEY (id),
324-
UNIQUE INDEX idx_service_state_service_id (service_id)
333+
334+
UNIQUE INDEX idx_service_state_service_id (service_id),
335+
INDEX idx_service_state_is_problem (is_problem, severity) COMMENT 'Service list filtered by is_problem ordered by severity',
336+
INDEX idx_service_state_severity (severity) COMMENT 'Service list filtered/ordered by severity',
337+
INDEX idx_service_state_soft_state (soft_state, last_state_change) COMMENT 'Service list filtered/ordered by soft_state; recently recovered filter',
338+
INDEX idx_service_state_last_state_change (last_state_change) COMMENT 'Service list filtered/ordered by last_state_change'
325339
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
326340

327341
CREATE TABLE endpoint (
@@ -574,7 +588,9 @@ CREATE TABLE comment (
574588
PRIMARY KEY (id),
575589

576590
INDEX idx_comment_name (name) COMMENT 'Comment detail filter',
577-
INDEX idx_comment_entry_time (entry_time) COMMENT 'Comment list fileted/ordered by entry_time'
591+
INDEX idx_comment_entry_time (entry_time) COMMENT 'Comment list fileted/ordered by entry_time',
592+
INDEX idx_comment_author (author) COMMENT 'Comment list filtered/ordered by author',
593+
INDEX idx_comment_expire_time (expire_time) COMMENT 'Comment list filtered/ordered by expire_time'
578594
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
579595

580596
CREATE TABLE downtime (
@@ -611,7 +627,14 @@ CREATE TABLE downtime (
611627
PRIMARY KEY (id),
612628

613629
INDEX idx_downtime_is_in_effect (is_in_effect, start_time) COMMENT 'Downtime list filtered/ordered by severity',
614-
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter'
630+
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter',
631+
INDEX idx_downtime_entry_time (entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
632+
INDEX idx_downtime_start_time (start_time) COMMENT 'Downtime list filtered/ordered by start_time',
633+
INDEX idx_downtime_end_time (end_time) COMMENT 'Downtime list filtered/ordered by end_time',
634+
INDEX idx_downtime_scheduled_start_time (scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
635+
INDEX idx_downtime_scheduled_end_time (scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
636+
INDEX idx_downtime_author (author) COMMENT 'Downtime list filtered/ordered by author',
637+
INDEX idx_downtime_duration (duration) COMMENT 'Downtime list filtered/ordered by duration'
615638
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
616639

617640
CREATE TABLE notification (
@@ -639,8 +662,8 @@ CREATE TABLE notification (
639662

640663
PRIMARY KEY (id),
641664

642-
INDEX idx_host_id (host_id),
643-
INDEX idx_service_id (service_id)
665+
INDEX idx_notification_host_id (host_id),
666+
INDEX idx_notification_service_id (service_id)
644667
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
645668

646669
CREATE TABLE notification_user (
@@ -903,8 +926,9 @@ CREATE TABLE zone (
903926
depth tinyint unsigned NOT NULL,
904927

905928
PRIMARY KEY (id),
906-
INDEX idx_parent_id (parent_id),
907-
UNIQUE INDEX idx_environment_id_id (environment_id,id)
929+
930+
UNIQUE INDEX idx_environment_id_id (environment_id, id),
931+
INDEX idx_zone_parent_id (parent_id)
908932
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
909933

910934
CREATE TABLE notification_history (
@@ -926,7 +950,7 @@ CREATE TABLE notification_history (
926950

927951
PRIMARY KEY (id),
928952

929-
INDEX idx_notification_history_event_time (send_time DESC) COMMENT 'Notification list filtered/ordered by entry_time'
953+
INDEX idx_notification_history_send_time (send_time DESC) COMMENT 'Notification list filtered/ordered by send_time'
930954
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
931955

932956
CREATE TABLE user_notification_history (
@@ -1084,7 +1108,8 @@ CREATE TABLE history (
10841108
INDEX idx_history_downtime (downtime_history_id),
10851109
INDEX idx_history_flapping (flapping_history_id),
10861110
INDEX idx_history_notification (notification_history_id),
1087-
INDEX idx_history_state (state_history_id)
1111+
INDEX idx_history_state (state_history_id),
1112+
INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host/service history detail filter'
10881113
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
10891114

10901115
CREATE TABLE icingadb_schema (

schema/mysql/upgrades/1.0.0-rc2.sql

+48
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,51 @@ UPDATE downtime SET scheduled_duration = scheduled_end_time - scheduled_start_ti
418418

419419
ALTER TABLE service_state ADD COLUMN host_id binary(20) NOT NULL COMMENT 'host.id' AFTER id;
420420
UPDATE service_state INNER JOIN service ON service.id = service_state.service_id SET service_state.host_id = service.host_id WHERE service_state.host_id = REPEAT('\0', 20);
421+
422+
ALTER TABLE comment
423+
ADD INDEX idx_comment_author (author) COMMENT 'Comment list filtered/ordered by author',
424+
ADD INDEX idx_comment_expire_time (expire_time) COMMENT 'Comment list filtered/ordered by expire_time';
425+
426+
ALTER TABLE downtime
427+
ADD INDEX idx_downtime_entry_time (entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
428+
ADD INDEX idx_downtime_start_time (start_time) COMMENT 'Downtime list filtered/ordered by start_time',
429+
ADD INDEX idx_downtime_end_time (end_time) COMMENT 'Downtime list filtered/ordered by end_time',
430+
ADD INDEX idx_downtime_scheduled_start_time (scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
431+
ADD INDEX idx_downtime_scheduled_end_time (scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
432+
ADD INDEX idx_downtime_author (author) COMMENT 'Downtime list filtered/ordered by author',
433+
ADD INDEX idx_downtime_duration (duration) COMMENT 'Downtime list filtered/ordered by duration';
434+
435+
ALTER TABLE service_state
436+
ADD INDEX idx_service_state_is_problem (is_problem, severity) COMMENT 'Service list filtered by is_problem ordered by severity',
437+
ADD INDEX idx_service_state_severity (severity) COMMENT 'Service list filtered/ordered by severity',
438+
ADD INDEX idx_service_state_soft_state (soft_state, last_state_change) COMMENT 'Service list filtered/ordered by soft_state; recently recovered filter',
439+
ADD INDEX idx_service_state_last_state_change (last_state_change) COMMENT 'Service list filtered/ordered by last_state_change';
440+
441+
ALTER TABLE host_state
442+
ADD INDEX idx_host_state_is_problem (is_problem, severity) COMMENT 'Host list filtered by is_problem ordered by severity',
443+
ADD INDEX idx_host_state_severity (severity) COMMENT 'Host list filtered/ordered by severity',
444+
ADD INDEX idx_host_state_soft_state (soft_state, last_state_change) COMMENT 'Host list filtered/ordered by soft_state; recently recovered filter',
445+
ADD INDEX idx_host_state_last_state_change (last_state_change) COMMENT 'Host list filtered/ordered by last_state_change';
446+
447+
ALTER TABLE hostgroup
448+
ADD INDEX idx_hostroup_name (name) COMMENT 'Host/service/host group list filtered by host group name';
449+
450+
ALTER TABLE servicegroup
451+
ADD INDEX idx_servicegroup_name (name) COMMENT 'Host/service/service group list filtered by service group name';
452+
453+
ALTER TABLE notification
454+
DROP INDEX idx_host_id,
455+
DROP INDEX idx_service_id,
456+
ADD INDEX idx_notification_host_id (host_id),
457+
ADD INDEX idx_notification_service_id (service_id);
458+
459+
ALTER TABLE zone
460+
DROP INDEX idx_parent_id,
461+
ADD INDEX idx_zone_parent_id (parent_id);
462+
463+
ALTER TABLE history
464+
ADD INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host/service history detail filter';
465+
466+
ALTER TABLE notification_history
467+
DROP INDEX idx_notification_history_event_time,
468+
ADD INDEX idx_notification_history_send_time (send_time) COMMENT 'Notification list filtered/ordered by send_time';

0 commit comments

Comments
 (0)