Skip to content

Commit ccf2265

Browse files
committed
Merge pull request #1466 from nvazquez/graldboptimization
CLOUDSTACK-9340: General DB Optimization## Description In some production environments there were being experimented delays in most of the jobs. A search for DB optimization was taken and some deficiencies were discovered, we can group them in 4 groups: * Incorrect PRIMARY key * Duplicate PRIMARY KEY * Missing indexes (Add indexes to avoid full table scans) * Some views query (Change view to improve account retrieval speed) * pr/1466: CLOUDSTACK-9340: General DB Optimization Signed-off-by: Will Stevens <williamstevens@gmail.com>
2 parents 726ee47 + 8b6e618 commit ccf2265

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

setup/db/db/schema-481to490-cleanup.sql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,68 @@
1818
--;
1919
-- Schema cleanup from 4.8.1 to 4.9.0;
2020
--;
21+
22+
-- Added in CLOUDSTACK-9340: General DB optimization, 4 cases:
23+
24+
----- 1) Incorrect PRIMARY key
25+
ALTER TABLE `cloud`.`ovs_tunnel_network`
26+
DROP PRIMARY KEY,
27+
ADD PRIMARY KEY (`id`),
28+
DROP INDEX `id` ,
29+
ADD UNIQUE INDEX `i_to_from_network_id` (`to` ASC, `from` ASC, `network_id` ASC);
30+
31+
----- 2) Duplicate PRIMARY KEY
32+
ALTER TABLE `cloud`.`user_vm` DROP INDEX `id_2` ,DROP INDEX `id` ;
33+
ALTER TABLE `cloud`.`domain_router` DROP INDEX `id_2` ,DROP INDEX `id` ;
34+
ALTER TABLE `cloud`.`vm_instance` DROP INDEX `id_2` ,DROP INDEX `id` ;
35+
ALTER TABLE `cloud`.`account_vlan_map` DROP INDEX `id` ;
36+
ALTER TABLE `cloud`.`account_vnet_map` DROP INDEX `id` ;
37+
ALTER TABLE `cloud`.`baremetal_rct` DROP INDEX `id` ;
38+
ALTER TABLE `cloud`.`cluster` DROP INDEX `id` ;
39+
ALTER TABLE `cloud`.`conditions` DROP INDEX `id` ;
40+
ALTER TABLE `cloud`.`counter` DROP INDEX `id` ;
41+
ALTER TABLE `cloud`.`data_center` DROP INDEX `id` ;
42+
ALTER TABLE `cloud`.`dc_storage_network_ip_range` DROP INDEX `id` ;
43+
ALTER TABLE `cloud`.`dedicated_resources` DROP INDEX `id` ;
44+
ALTER TABLE `cloud`.`host_pod_ref` DROP INDEX `id` ;
45+
ALTER TABLE `cloud`.`iam_group` DROP INDEX `id` ;
46+
ALTER TABLE `cloud`.`iam_policy` DROP INDEX `id` ;
47+
ALTER TABLE `cloud`.`iam_policy_permission` DROP INDEX `id` ;
48+
ALTER TABLE `cloud`.`image_store_details` DROP INDEX `id` ;
49+
ALTER TABLE `cloud`.`instance_group` DROP INDEX `id` ;
50+
ALTER TABLE `cloud`.`netapp_lun` DROP INDEX `id` ;
51+
ALTER TABLE `cloud`.`netapp_pool` DROP INDEX `id` ;
52+
ALTER TABLE `cloud`.`netapp_volume` DROP INDEX `id` ;
53+
ALTER TABLE `cloud`.`network_acl_item_cidrs` DROP INDEX `id` ;
54+
ALTER TABLE `cloud`.`network_offerings` DROP INDEX `id` ;
55+
ALTER TABLE `cloud`.`nic_secondary_ips` DROP INDEX `id` ;
56+
ALTER TABLE `cloud`.`nics` DROP INDEX `id` ;
57+
ALTER TABLE `cloud`.`op_ha_work` DROP INDEX `id` ;
58+
ALTER TABLE `cloud`.`op_host` DROP INDEX `id` ;
59+
ALTER TABLE `cloud`.`op_host_transfer` DROP INDEX `id` ;
60+
ALTER TABLE `cloud`.`op_networks` DROP INDEX `id` ;
61+
ALTER TABLE `cloud`.`op_nwgrp_work` DROP INDEX `id` ;
62+
ALTER TABLE `cloud`.`op_vm_ruleset_log` DROP INDEX `id` ;
63+
ALTER TABLE `cloud`.`op_vpc_distributed_router_sequence_no` DROP INDEX `id` ;
64+
ALTER TABLE `cloud`.`pod_vlan_map` DROP INDEX `id` ;
65+
ALTER TABLE `cloud`.`portable_ip_address` DROP INDEX `id` ;
66+
ALTER TABLE `cloud`.`portable_ip_range` DROP INDEX `id` ;
67+
ALTER TABLE `cloud`.`region` DROP INDEX `id` ;
68+
ALTER TABLE `cloud`.`remote_access_vpn` DROP INDEX `id` ;
69+
ALTER TABLE `cloud`.`snapshot_details` DROP INDEX `id` ;
70+
ALTER TABLE `cloud`.`snapshots` DROP INDEX `id` ;
71+
ALTER TABLE `cloud`.`storage_pool` DROP INDEX `id` ;
72+
ALTER TABLE `cloud`.`storage_pool_details` DROP INDEX `id` ;
73+
ALTER TABLE `cloud`.`storage_pool_work` DROP INDEX `id` ;
74+
ALTER TABLE `cloud`.`user_ip_address` DROP INDEX `id` ;
75+
ALTER TABLE `cloud`.`user_ipv6_address` DROP INDEX `id` ;
76+
ALTER TABLE `cloud`.`user_statistics` DROP INDEX `id` ;
77+
ALTER TABLE `cloud`.`version` DROP INDEX `id` ;
78+
ALTER TABLE `cloud`.`vlan` DROP INDEX `id` ;
79+
ALTER TABLE `cloud`.`vm_disk_statistics` DROP INDEX `id` ;
80+
ALTER TABLE `cloud`.`vm_snapshot_details` DROP INDEX `id` ;
81+
ALTER TABLE `cloud`.`vm_work_job` DROP INDEX `id` ;
82+
ALTER TABLE `cloud`.`vpc_gateways` DROP INDEX `id` ;
83+
ALTER TABLE `cloud`.`vpn_users` DROP INDEX `id` ;
84+
85+

setup/db/db/schema-481to490.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,26 @@ VIEW `user_vm_view` AS
413413

414414
-- Add cluster.storage.operations.exclude property
415415
INSERT INTO `cloud`.`configuration` (`category`, `instance`, `component`, `name`, `description`, `default_value`, `updated`, `scope`, `is_dynamic`) VALUES ('Advanced', 'DEFAULT', 'CapacityManager', 'cluster.storage.operations.exclude', 'Exclude cluster from storage operations', 'false', now(), 'Cluster', '1');
416+
417+
----- 3) Missing indexes (Add indexes to avoid full table scans)
418+
ALTER TABLE `cloud`.`op_it_work` ADD INDEX `i_type_and_updated` (`type` ASC, `updated_at` ASC);
419+
ALTER TABLE `cloud`.`vm_root_disk_tags` ADD INDEX `i_vm_id` (`vm_id` ASC);
420+
ALTER TABLE `cloud`.`vm_compute_tags` ADD INDEX `i_vm_id` (`vm_id` ASC);
421+
ALTER TABLE `cloud`.`vm_network_map` ADD INDEX `i_vm_id` (`vm_id` ASC);
422+
ALTER TABLE `cloud`.`ssh_keypairs` ADD INDEX `i_public_key` (`public_key` (64) ASC);
423+
ALTER TABLE `cloud`.`user_vm_details` ADD INDEX `i_name_vm_id` (`vm_id` ASC, `name` ASC);
424+
ALTER TABLE `cloud`.`instance_group` ADD INDEX `i_name` (`name` ASC);
425+
426+
----- 4) Some views query (Change view to improve account retrieval speed)
427+
CREATE OR REPLACE
428+
VIEW `account_vmstats_view` AS
429+
SELECT
430+
`vm_instance`.`account_id` AS `account_id`,
431+
`vm_instance`.`state` AS `state`,
432+
COUNT(0) AS `vmcount`
433+
FROM
434+
`vm_instance`
435+
WHERE
436+
(`vm_instance`.`vm_type` = 'User' and `vm_instance`.`removed` is NULL)
437+
GROUP BY `vm_instance`.`account_id` , `vm_instance`.`state`;
438+
-- End CLOUDSTACK-9340

0 commit comments

Comments
 (0)