Skip to content

Commit b4ad5a2

Browse files
committed
Schema: Add more mysql indexes
1 parent 54dbe0c commit b4ad5a2

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

schema/mysql/schema.sql

+24-7
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ CREATE TABLE host_state (
162162
next_update bigint unsigned NOT NULL,
163163

164164
PRIMARY KEY (id),
165-
UNIQUE INDEX idx_host_state_host_id (host_id)
165+
UNIQUE INDEX idx_host_state_host_id(host_id),
166+
INDEX idx_host_state_severity(severity) COMMENT 'Host list filtered/ordered by severity',
167+
INDEX idx_host_state_soft_state(soft_state) COMMENT 'Host list filtered/ordered by soft_state',
168+
INDEX idx_host_state_last_state_change(last_state_change) COMMENT 'Host list filtered/ordered by last_state_change'
166169
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
167170

168171
CREATE TABLE service (
@@ -320,7 +323,11 @@ CREATE TABLE service_state (
320323
next_update bigint unsigned NOT NULL,
321324

322325
PRIMARY KEY (id),
323-
UNIQUE INDEX idx_service_state_service_id (service_id)
326+
UNIQUE INDEX idx_service_state_service_id(service_id, host_id, severity, last_state_change, soft_state),
327+
UNIQUE INDEX idx_service_state_host_id(host_id, service_id, severity, last_state_change, soft_state),
328+
UNIQUE INDEX idx_service_state_severity(severity, host_id, service_id, last_state_change, soft_state),
329+
UNIQUE INDEX idx_service_state_soft_state(soft_state, host_id, service_id, severity, last_state_change),
330+
UNIQUE INDEX idx_service_state_last_state_change(last_state_change, host_id, service_id, severity, soft_state)
324331
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
325332

326333
CREATE TABLE endpoint (
@@ -584,7 +591,9 @@ CREATE TABLE comment (
584591
PRIMARY KEY (id),
585592

586593
INDEX idx_comment_name (name) COMMENT 'Comment detail filter',
587-
INDEX idx_comment_entry_time (entry_time) COMMENT 'Comment list fileted/ordered by entry_time'
594+
INDEX idx_comment_entry_time(entry_time) COMMENT 'Comment list filtered/ordered by entry_time',
595+
INDEX idx_comment_expire_time(expire_time) COMMENT 'Comment list filtered/ordered by expire_time',
596+
INDEX idx_comment_author(author) COMMENT 'Comment list filtered/ordered by author'
588597
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
589598

590599
CREATE TABLE downtime (
@@ -618,8 +627,15 @@ CREATE TABLE downtime (
618627

619628
PRIMARY KEY (id),
620629

621-
INDEX idx_downtime_is_in_effect (is_in_effect, start_time) COMMENT 'Downtime list filtered/ordered by severity',
622-
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter'
630+
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter',
631+
INDEX idx_downtime_is_in_effect(is_in_effect, start_time) COMMENT 'Downtime list filtered/ordered by is_in_effect',
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_entry_time(entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
635+
INDEX idx_downtime_scheduled_start_time(scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
636+
INDEX idx_downtime_scheduled_end_time(scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
637+
INDEX idx_downtime_author(author) COMMENT 'Downtime list filtered/ordered by author',
638+
INDEX idx_downtime_duration(duration) COMMENT 'Downtime list filtered/ordered by duration'
623639
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
624640

625641
CREATE TABLE notification (
@@ -1086,11 +1102,12 @@ CREATE TABLE history (
10861102
CONSTRAINT fk_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE,
10871103
CONSTRAINT fk_history_state_history FOREIGN KEY (state_history_id) REFERENCES state_history (id) ON DELETE CASCADE,
10881104

1089-
INDEX idx_history_event_time (event_time) COMMENT 'History filtered/ordered by event_time',
10901105
INDEX idx_history_acknowledgement (acknowledgement_history_id),
10911106
INDEX idx_history_comment (comment_history_id),
10921107
INDEX idx_history_downtime (downtime_history_id),
10931108
INDEX idx_history_flapping (flapping_history_id),
10941109
INDEX idx_history_notification (notification_history_id),
1095-
INDEX idx_history_state (state_history_id)
1110+
INDEX idx_history_state (state_history_id),
1111+
INDEX idx_history_event_time (event_time, host_id) COMMENT 'History list filtered/ordered by event_time',
1112+
INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host history list filtered/ordered by host_id|service_id'
10961113
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

schema/mysql/upgrades/1.0.0-rc2.sql

+27-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ ALTER TABLE host_state ADD PRIMARY KEY (id);
55
ALTER TABLE host_state ADD COLUMN properties_checksum binary(20) AFTER environment_id;
66
UPDATE host_state SET properties_checksum = 0;
77
ALTER TABLE host_state MODIFY COLUMN properties_checksum binary(20) COMMENT 'sha1(all properties)' NOT NULL;
8-
ALTER TABLE host_state ADD UNIQUE INDEX idx_host_state_host_id (host_id);
8+
ALTER TABLE host_state
9+
ADD INDEX idx_host_state_severity(severity) COMMENT 'Host list filtered/ordered by severity',
10+
ADD INDEX idx_host_state_soft_state(soft_state) COMMENT 'Host list filtered/ordered by soft_state',
11+
ADD INDEX idx_host_state_last_state_change(last_state_change) COMMENT 'Host list filtered/ordered by last_state_change';
912

1013
ALTER TABLE service_state DROP PRIMARY KEY;
1114
ALTER TABLE service_state ADD COLUMN id binary(20) NOT NULL COMMENT 'service.id' FIRST;
@@ -14,11 +17,25 @@ ALTER TABLE service_state ADD PRIMARY KEY (id);
1417
ALTER TABLE service_state ADD COLUMN properties_checksum binary(20) AFTER environment_id;
1518
UPDATE service_state SET properties_checksum = 0;
1619
ALTER TABLE service_state MODIFY COLUMN properties_checksum binary(20) COMMENT 'sha1(all properties)' NOT NULL;
17-
ALTER TABLE service_state ADD UNIQUE INDEX idx_service_state_service_id (service_id);
20+
ALTER TABLE service_state
21+
DROP INDEX idx_service_state_service_id,
22+
ADD UNIQUE INDEX idx_service_state_service_id(service_id, host_id, severity, last_state_change, soft_state),
23+
ADD UNIQUE INDEX idx_service_state_host_id(host_id, service_id, severity, last_state_change, soft_state),
24+
ADD UNIQUE INDEX idx_service_state_severity(severity, host_id, service_id, last_state_change, soft_state),
25+
ADD UNIQUE INDEX idx_service_state_soft_state(soft_state, host_id, service_id, severity, last_state_change),
26+
ADD UNIQUE INDEX idx_service_state_last_state_change(last_state_change, host_id, service_id, severity, soft_state);
1827

1928
ALTER TABLE downtime
2029
ADD COLUMN parent_id binary(20) COMMENT 'For service downtimes, the ID of the host downtime that created this downtime by using the "all_services" flag of the schedule-downtime API.' AFTER triggered_by_id,
2130
MODIFY COLUMN triggered_by_id binary(20) COMMENT 'The ID of the downtime that triggered this downtime. This is set when creating downtimes on a host or service higher up in the dependency chain using the "child_option" "DowntimeTriggeredChildren" and can also be set manually via the API.';
31+
ALTER TABLE downtime
32+
ADD INDEX idx_downtime_entry_time(entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
33+
ADD INDEX idx_downtime_start_time(start_time) COMMENT 'Downtime list filtered/ordered by start_time',
34+
ADD INDEX idx_downtime_end_time(end_time) COMMENT 'Downtime list filtered/ordered by end_time',
35+
ADD INDEX idx_downtime_scheduled_start_time(scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
36+
ADD INDEX idx_downtime_scheduled_end_time(scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
37+
ADD INDEX idx_downtime_author(author) COMMENT 'Downtime list filtered/ordered by author',
38+
ADD INDEX idx_downtime_duration(duration) COMMENT 'Downtime list filtered/ordered by duration';
2239
ALTER TABLE downtime_history
2340
ADD COLUMN parent_id binary(20) COMMENT 'For service downtimes, the ID of the host downtime that created this downtime by using the "all_services" flag of the schedule-downtime API.' AFTER triggered_by_id,
2441
MODIFY COLUMN triggered_by_id binary(20) COMMENT 'The ID of the downtime that triggered this downtime. This is set when creating downtimes on a host or service higher up in the dependency chain using the "child_option" "DowntimeTriggeredChildren" and can also be set manually via the API.';
@@ -191,6 +208,10 @@ ALTER TABLE history
191208
ADD CONSTRAINT fk_history_flapping_history FOREIGN KEY (flapping_history_id) REFERENCES flapping_history (id) ON DELETE CASCADE,
192209
ADD CONSTRAINT fk_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE,
193210
ADD CONSTRAINT fk_history_state_history FOREIGN KEY (state_history_id) REFERENCES state_history (id) ON DELETE CASCADE;
211+
ALTER TABLE history
212+
DROP INDEX idx_history_event_time,
213+
ADD INDEX idx_history_event_time (event_time, host_id) COMMENT 'History list filtered/ordered by event_time',
214+
ADD INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host history list filtered/ordered by host_id|service_id';
194215

195216
ALTER TABLE user_notification_history
196217
ADD CONSTRAINT fk_user_notification_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE;
@@ -322,3 +343,7 @@ ALTER TABLE flapping_history
322343
MODIFY id binary(20) NOT NULL COMMENT 'sha1(environment.id + "Host"|"Service" + host|service.name + start_time)';
323344
ALTER TABLE acknowledgement_history
324345
MODIFY id binary(20) NOT NULL COMMENT 'sha1(environment.id + "Host"|"Service" + host|service.name + set_time)';
346+
347+
ALTER TABLE comment
348+
ADD INDEX idx_comment_expire_time(expire_time) COMMENT 'Comment list filtered/ordered by expire_time',
349+
ADD INDEX idx_comment_author(author) COMMENT 'Comment list filtered/ordered by author';

0 commit comments

Comments
 (0)