Skip to content

Commit b03b706

Browse files
committed
Schema: Add more mysql indexes
1 parent d9c626c commit b03b706

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

schema/mysql/schema.sql

+25-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, severity, last_state_change, soft_state),
166+
UNIQUE INDEX idx_host_state_severity(severity, host_id, last_state_change, soft_state),
167+
UNIQUE INDEX idx_host_state_soft_state(soft_state, host_id, severity, last_state_change),
168+
UNIQUE INDEX idx_host_state_last_state_change(last_state_change, host_id, severity, soft_state)
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, expire_time, author) COMMENT 'Comment list fileted/ordered by entry_time',
595+
INDEX idx_comment_expire_time(expire_time, entry_time, author) COMMENT 'Comment list fileted/ordered by expire_time',
596+
INDEX idx_comment_author(author, entry_time, expire_time) COMMENT 'Comment list fileted/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, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
632+
INDEX idx_downtime_start_time(start_time, is_in_effect, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
633+
INDEX idx_downtime_end_time(end_time, is_in_effect, start_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
634+
INDEX idx_downtime_entry_time(entry_time, is_in_effect, start_time, end_time, duration, scheduled_start_time, scheduled_end_time, author),
635+
INDEX idx_downtime_scheduled_start_time(scheduled_start_time, is_in_effect, start_time, end_time, duration, entry_time, scheduled_end_time, author),
636+
INDEX idx_downtime_scheduled_end_time(scheduled_end_time, is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, author),
637+
INDEX idx_downtime_author(author, is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time),
638+
INDEX idx_downtime_duration(duration, is_in_effect, start_time, end_time, entry_time, scheduled_start_time, scheduled_end_time, author)
623639
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
624640

625641
CREATE TABLE notification (
@@ -1086,11 +1102,13 @@ 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, service_id) COMMENT 'History filtered/ordered by event_time',
1112+
INDEX idx_history_host_id (host_id, service_id, event_time) COMMENT 'History filtered/ordered by host_id',
1113+
INDEX idx_history_service_id (service_id, host_id, event_time) COMMENT 'History list filtered/ordered by service_id'
10961114
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

schema/mysql/upgrades/1.0.0-rc2.sql

+34-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ 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+
DROP INDEX idx_host_state_host_id,
10+
ADD UNIQUE INDEX idx_host_state_host_id(host_id, severity, last_state_change, soft_state),
11+
ADD UNIQUE INDEX idx_host_state_severity(severity, host_id, last_state_change, soft_state),
12+
ADD UNIQUE INDEX idx_host_state_soft_state(soft_state, host_id, severity, last_state_change),
13+
ADD UNIQUE INDEX idx_host_state_last_state_change(last_state_change, host_id, severity, soft_state);
914

1015
ALTER TABLE service_state DROP PRIMARY KEY;
1116
ALTER TABLE service_state ADD COLUMN id binary(20) NOT NULL COMMENT 'service.id' FIRST;
@@ -14,11 +19,27 @@ ALTER TABLE service_state ADD PRIMARY KEY (id);
1419
ALTER TABLE service_state ADD COLUMN properties_checksum binary(20) AFTER environment_id;
1520
UPDATE service_state SET properties_checksum = 0;
1621
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);
22+
ALTER TABLE service_state
23+
DROP INDEX idx_service_state_service_id,
24+
ADD UNIQUE INDEX idx_service_state_service_id(service_id, host_id, severity, last_state_change, soft_state),
25+
ADD UNIQUE INDEX idx_service_state_host_id(host_id, service_id, severity, last_state_change, soft_state),
26+
ADD UNIQUE INDEX idx_service_state_severity(severity, host_id, service_id, last_state_change, soft_state),
27+
ADD UNIQUE INDEX idx_service_state_soft_state(soft_state, host_id, service_id, severity, last_state_change),
28+
ADD UNIQUE INDEX idx_service_state_last_state_change(last_state_change, host_id, service_id, severity, soft_state);
1829

1930
ALTER TABLE downtime
2031
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,
2132
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.';
33+
ALTER TABLE downtime
34+
DROP INDEX idx_downtime_is_in_effect,
35+
ADD INDEX idx_downtime_is_in_effect(is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
36+
ADD INDEX idx_downtime_start_time(start_time, is_in_effect, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
37+
ADD INDEX idx_downtime_end_time(end_time, is_in_effect, start_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author),
38+
ADD INDEX idx_downtime_entry_time(entry_time, is_in_effect, start_time, end_time, duration, scheduled_start_time, scheduled_end_time, author),
39+
ADD INDEX idx_downtime_scheduled_start_time(scheduled_start_time, is_in_effect, start_time, end_time, duration, entry_time, scheduled_end_time, author),
40+
ADD INDEX idx_downtime_scheduled_end_time(scheduled_end_time, is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, author),
41+
ADD INDEX idx_downtime_author(author, is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time),
42+
ADD INDEX idx_downtime_duration(duration, is_in_effect, start_time, end_time, duration, entry_time, scheduled_start_time, scheduled_end_time, author);
2243
ALTER TABLE downtime_history
2344
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,
2445
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.';
@@ -183,6 +204,17 @@ ALTER TABLE history
183204
ADD CONSTRAINT fk_history_flapping_history FOREIGN KEY (flapping_history_id) REFERENCES flapping_history (id) ON DELETE CASCADE,
184205
ADD CONSTRAINT fk_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE,
185206
ADD CONSTRAINT fk_history_state_history FOREIGN KEY (state_history_id) REFERENCES state_history (id) ON DELETE CASCADE;
207+
ALTER TABLE history
208+
DROP INDEX idx_history_event_time,
209+
ADD INDEX idx_history_event_time (event_time, host_id, service_id) COMMENT 'History filtered/ordered by event_time',
210+
ADD INDEX idx_history_host_id (host_id, service_id, event_time) COMMENT 'History filtered/ordered by host_id',
211+
ADD INDEX idx_history_service_id (service_id, host_id, event_time) COMMENT 'History list filtered/ordered by service_id';
186212

187213
ALTER TABLE user_notification_history
188214
ADD CONSTRAINT fk_user_notification_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE;
215+
216+
ALTER TABLE comment
217+
DROP INDEX idx_comment_entry_time,
218+
ADD INDEX idx_comment_entry_time(entry_time, expire_time, author) COMMENT 'Comment list fileted/ordered by entry_time',
219+
ADD INDEX idx_comment_expire_time(expire_time, entry_time, author) COMMENT 'Comment list fileted/ordered by expire_time',
220+
ADD INDEX idx_comment_author(author, entry_time, expire_time) COMMENT 'Comment list fileted/ordered by author';

0 commit comments

Comments
 (0)