Skip to content

Add more MySQL indexes #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ CREATE TABLE hostgroup (

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

PRIMARY KEY (id)
PRIMARY KEY (id),

INDEX idx_hostroup_name (name) COMMENT 'Host/service/host group list filtered by host group name'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE hostgroup_member (
Expand Down Expand Up @@ -162,7 +164,12 @@ CREATE TABLE host_state (
next_update bigint unsigned NOT NULL,

PRIMARY KEY (id),
UNIQUE INDEX idx_host_state_host_id (host_id)

UNIQUE INDEX idx_host_state_host_id (host_id),
INDEX idx_host_state_is_problem (is_problem, severity) COMMENT 'Host list filtered by is_problem ordered by severity',
INDEX idx_host_state_severity (severity) COMMENT 'Host list filtered/ordered by severity',
INDEX idx_host_state_soft_state (soft_state, last_state_change) COMMENT 'Host list filtered/ordered by soft_state; recently recovered filter',
INDEX idx_host_state_last_state_change (last_state_change) COMMENT 'Host list filtered/ordered by last_state_change'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE service (
Expand Down Expand Up @@ -236,7 +243,9 @@ CREATE TABLE servicegroup (

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

PRIMARY KEY (id)
PRIMARY KEY (id),

INDEX idx_servicegroup_name (name) COMMENT 'Host/service/service group list filtered by service group name'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE servicegroup_member (
Expand Down Expand Up @@ -321,7 +330,12 @@ CREATE TABLE service_state (
next_update bigint unsigned NOT NULL,

PRIMARY KEY (id),
UNIQUE INDEX idx_service_state_service_id (service_id)

UNIQUE INDEX idx_service_state_service_id (service_id),
INDEX idx_service_state_is_problem (is_problem, severity) COMMENT 'Service list filtered by is_problem ordered by severity',
INDEX idx_service_state_severity (severity) COMMENT 'Service list filtered/ordered by severity',
INDEX idx_service_state_soft_state (soft_state, last_state_change) COMMENT 'Service list filtered/ordered by soft_state; recently recovered filter',
INDEX idx_service_state_last_state_change (last_state_change) COMMENT 'Service list filtered/ordered by last_state_change'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE endpoint (
Expand Down Expand Up @@ -585,7 +599,9 @@ CREATE TABLE comment (
PRIMARY KEY (id),

INDEX idx_comment_name (name) COMMENT 'Comment detail filter',
INDEX idx_comment_entry_time (entry_time) COMMENT 'Comment list fileted/ordered by entry_time'
INDEX idx_comment_entry_time (entry_time) COMMENT 'Comment list fileted/ordered by entry_time',
INDEX idx_comment_author (author) COMMENT 'Comment list filtered/ordered by author',
INDEX idx_comment_expire_time (expire_time) COMMENT 'Comment list filtered/ordered by expire_time'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE downtime (
Expand Down Expand Up @@ -622,7 +638,14 @@ CREATE TABLE downtime (
PRIMARY KEY (id),

INDEX idx_downtime_is_in_effect (is_in_effect, start_time) COMMENT 'Downtime list filtered/ordered by severity',
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter'
INDEX idx_downtime_name (name) COMMENT 'Downtime detail filter',
INDEX idx_downtime_entry_time (entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
INDEX idx_downtime_start_time (start_time) COMMENT 'Downtime list filtered/ordered by start_time',
INDEX idx_downtime_end_time (end_time) COMMENT 'Downtime list filtered/ordered by end_time',
INDEX idx_downtime_scheduled_start_time (scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
INDEX idx_downtime_scheduled_end_time (scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
INDEX idx_downtime_author (author) COMMENT 'Downtime list filtered/ordered by author',
INDEX idx_downtime_duration (duration) COMMENT 'Downtime list filtered/ordered by duration'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE notification (
Expand Down Expand Up @@ -650,8 +673,8 @@ CREATE TABLE notification (

PRIMARY KEY (id),

INDEX idx_host_id (host_id),
INDEX idx_service_id (service_id)
INDEX idx_notification_host_id (host_id),
INDEX idx_notification_service_id (service_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE notification_user (
Expand Down Expand Up @@ -914,8 +937,9 @@ CREATE TABLE zone (
depth tinyint unsigned NOT NULL,

PRIMARY KEY (id),
INDEX idx_parent_id (parent_id),
UNIQUE INDEX idx_environment_id_id (environment_id,id)

UNIQUE INDEX idx_environment_id_id (environment_id, id),
INDEX idx_zone_parent_id (parent_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE notification_history (
Expand All @@ -937,7 +961,7 @@ CREATE TABLE notification_history (

PRIMARY KEY (id),

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

CREATE TABLE user_notification_history (
Expand Down Expand Up @@ -1095,5 +1119,6 @@ CREATE TABLE history (
INDEX idx_history_downtime (downtime_history_id),
INDEX idx_history_flapping (flapping_history_id),
INDEX idx_history_notification (notification_history_id),
INDEX idx_history_state (state_history_id)
INDEX idx_history_state (state_history_id),
INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host/service history detail filter'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
48 changes: 48 additions & 0 deletions schema/mysql/upgrades/1.0.0-rc2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,51 @@ UPDATE downtime SET scheduled_duration = scheduled_end_time - scheduled_start_ti

ALTER TABLE service_state ADD COLUMN host_id binary(20) NOT NULL COMMENT 'host.id' AFTER id;
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);

ALTER TABLE comment
ADD INDEX idx_comment_author (author) COMMENT 'Comment list filtered/ordered by author',
ADD INDEX idx_comment_expire_time (expire_time) COMMENT 'Comment list filtered/ordered by expire_time';

ALTER TABLE downtime
ADD INDEX idx_downtime_entry_time (entry_time) COMMENT 'Downtime list filtered/ordered by entry_time',
ADD INDEX idx_downtime_start_time (start_time) COMMENT 'Downtime list filtered/ordered by start_time',
ADD INDEX idx_downtime_end_time (end_time) COMMENT 'Downtime list filtered/ordered by end_time',
ADD INDEX idx_downtime_scheduled_start_time (scheduled_start_time) COMMENT 'Downtime list filtered/ordered by scheduled_start_time',
ADD INDEX idx_downtime_scheduled_end_time (scheduled_end_time) COMMENT 'Downtime list filtered/ordered by scheduled_end_time',
ADD INDEX idx_downtime_author (author) COMMENT 'Downtime list filtered/ordered by author',
ADD INDEX idx_downtime_duration (duration) COMMENT 'Downtime list filtered/ordered by duration';

ALTER TABLE service_state
ADD INDEX idx_service_state_is_problem (is_problem, severity) COMMENT 'Service list filtered by is_problem ordered by severity',
ADD INDEX idx_service_state_severity (severity) COMMENT 'Service list filtered/ordered by severity',
ADD INDEX idx_service_state_soft_state (soft_state, last_state_change) COMMENT 'Service list filtered/ordered by soft_state; recently recovered filter',
ADD INDEX idx_service_state_last_state_change (last_state_change) COMMENT 'Service list filtered/ordered by last_state_change';

ALTER TABLE host_state
ADD INDEX idx_host_state_is_problem (is_problem, severity) COMMENT 'Host list filtered by is_problem ordered by severity',
ADD INDEX idx_host_state_severity (severity) COMMENT 'Host list filtered/ordered by severity',
ADD INDEX idx_host_state_soft_state (soft_state, last_state_change) COMMENT 'Host list filtered/ordered by soft_state; recently recovered filter',
ADD INDEX idx_host_state_last_state_change (last_state_change) COMMENT 'Host list filtered/ordered by last_state_change';

ALTER TABLE hostgroup
ADD INDEX idx_hostroup_name (name) COMMENT 'Host/service/host group list filtered by host group name';

ALTER TABLE servicegroup
ADD INDEX idx_servicegroup_name (name) COMMENT 'Host/service/service group list filtered by service group name';

ALTER TABLE notification
DROP INDEX idx_host_id,
DROP INDEX idx_service_id,
ADD INDEX idx_notification_host_id (host_id),
ADD INDEX idx_notification_service_id (service_id);

ALTER TABLE zone
DROP INDEX idx_parent_id,
ADD INDEX idx_zone_parent_id (parent_id);

ALTER TABLE history
ADD INDEX idx_history_host_service_id (host_id, service_id, event_time) COMMENT 'Host/service history detail filter';

ALTER TABLE notification_history
DROP INDEX idx_notification_history_event_time,
ADD INDEX idx_notification_history_send_time (send_time) COMMENT 'Notification list filtered/ordered by send_time';