From 076a712fbe5d14a83c7f937fa57590fbb3e6dc35 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 8 May 2024 18:01:39 +0530 Subject: [PATCH] schema: add indexes that save DB from too many scans Speeds up several APIs, esp host and VM listing APIs and VM deployment Signed-off-by: Rohit Yadav --- .../META-INF/db/schema-41800to41810.sql | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41800to41810.sql b/engine/schema/src/main/resources/META-INF/db/schema-41800to41810.sql index 0e1b6e49190..849c2230c8a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41800to41810.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41800to41810.sql @@ -433,9 +433,25 @@ ALTER TABLE `cloud`.`resource_reservation` MODIFY COLUMN `amount` bigint NOT NULL; -- Scalability and DB optimisations -ALTER TABLE `cloud`.`host` ADD INDEX `i_host__type` (`type`); +ALTER TABLE `cloud`.`host` ADD INDEX `i_host__mgmt_server_id` (`mgmt_server_id`); +ALTER TABLE `cloud`.`host` ADD INDEX `i_host__resource` (`resource`); ALTER TABLE `cloud`.`host` ADD INDEX `i_host__resource_state` (`resource_state`); +ALTER TABLE `cloud`.`host` ADD INDEX `i_host__type` (`type`); + +ALTER TABLE `cloud`.`user_ip_address` ADD INDEX `i_user_ip_address__vm_id` (`vm_id`); +ALTER TABLE `cloud`.`user_ip_address` ADD INDEX `i_user_ip_address__public_ip_address` (`public_ip_address`); +ALTER TABLE `cloud`.`user_ip_address` ADD INDEX `i_user_ip_address__data_center_id` (`data_center_id`); +ALTER TABLE `cloud`.`user_ip_address` ADD INDEX `i_user_ip_address__vlan_db_id` (`vlan_db_id`); + +ALTER TABLE `cloud`.`resource_tags` ADD INDEX `i_resource_tags__resource_id__resource_type` (`resource_id`, `resource_type`); + +ALTER TABLE `cloud`.`vlan` ADD INDEX `i_vlan__vlan_type` (`vlan_type`); + +ALTER TABLE `cloud`.`service_offering` ADD INDEX `i_service_offering__cpu` (`cpu`); +ALTER TABLE `cloud`.`service_offering` ADD INDEX `i_service_offering__speed` (`speed`); +ALTER TABLE `cloud`.`service_offering` ADD INDEX `i_service_offering__ram_size` (`ram_size`); + +ALTER TABLE `cloud`.`op_host_planner_reservation` ADD INDEX `i_op_host_planner_reservation__resource_usage`(`resource_usage`); ALTER TABLE `cloud`.`storage_pool` ADD INDEX `i_storage_pool__pool_type` (`pool_type`); -ALTER TABLE op_host_planner_reservation ADD INDEX `i_op_host_planner_reservation__resource_usage`(`resource_usage`);