mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
move adding indexes to java class
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
bb5a2966b1
commit
fd424d55f4
@ -113,6 +113,17 @@ public class DatabaseAccessObject {
|
||||
}
|
||||
}
|
||||
|
||||
public void renameIndex(Connection conn, String tableName, String oldName, String newName) {
|
||||
String stmt = String.format("ALTER TABLE %s RENAME INDEX %s TO %s", tableName, oldName, newName);
|
||||
s_logger.debug(String.format("Statement: %s", stmt));
|
||||
try (PreparedStatement pstmt = conn.prepareStatement(stmt)) {
|
||||
pstmt.execute();
|
||||
s_logger.debug(String.format("Renamed index %s to %s", oldName, newName));
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn(String.format("Unable to rename index %s to %s", oldName, newName), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void closePreparedStatement(PreparedStatement pstmt, String errorMessage) {
|
||||
try {
|
||||
if (pstmt != null) {
|
||||
|
||||
@ -31,6 +31,12 @@ public class DbUpgradeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void renameIndexIfNeeded(Connection conn, String tableName, String oldName, String newName) {
|
||||
if (!dao.indexExists(conn, tableName, oldName)) {
|
||||
dao.renameIndex(conn, tableName, oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addForeignKey(Connection conn, String tableName, String tableColumn, String foreignTableName, String foreignColumnName) {
|
||||
dao.addForeignKey(conn, tableName, tableColumn, foreignTableName, foreignColumnName);
|
||||
}
|
||||
|
||||
@ -258,6 +258,42 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "cluster_details", "name");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "vm_stats", "vm_id");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "host", "mgmt_server_id");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "host", "resource");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "host", "resource_state");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "host", "type");
|
||||
|
||||
DbUpgradeUtils.renameIndexIfNeeded(conn, "user_ip_address", "public_ip_address", "uk_public_ip_address");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "user_ip_address", "public_ip_address");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "user_ip_address", "data_center_id");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "user_ip_address", "vlan_db_id");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "user_ip_address", "removed");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "vlan", "vlan_type");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "vlan", "data_center_id");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "vlan", "removed");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "network_offering_details", "name");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "network_offering_details", "resource_id", "resource_type");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "cpu");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "speed");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "ram_size");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "op_host_planner_reservation", "resource_usage");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "storage_pool", "pool_type");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "storage_pool", "data_center_id", "status", "scope", "hypervisor");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "router_network_ref", "guest_type");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "domain_router", "role");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "async_job", "instance_type", "job_status");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "cluster", "managed_state");
|
||||
}
|
||||
|
||||
private void checkAndUpdateAffinityGroupNameCharSetToUtf8mb4(Connection conn) {
|
||||
|
||||
@ -591,44 +591,6 @@ ALTER TABLE `cloud`.`vpc_offerings` MODIFY `display_text` VARCHAR(255) CHARACTER
|
||||
|
||||
-- Scalability and DB optimisations
|
||||
|
||||
-- Host additions and listing
|
||||
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`);
|
||||
|
||||
-- IP address and VM view listing speed ups
|
||||
ALTER TABLE `cloud`.`user_ip_address` RENAME INDEX `public_ip_address` TO `uk_public_ip_address`;
|
||||
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`.`user_ip_address` ADD INDEX `i_user_ip_address__removed` (`removed`);
|
||||
|
||||
ALTER TABLE `cloud`.`vlan` ADD INDEX `i_vlan__vlan_type` (`vlan_type`);
|
||||
ALTER TABLE `cloud`.`vlan` ADD INDEX `i_vlan__data_center_id` (`data_center_id`);
|
||||
ALTER TABLE `cloud`.`vlan` ADD INDEX `i_vlan__removed` (`removed`);
|
||||
|
||||
ALTER TABLE `cloud`.`network_offering_details` ADD INDEX `i_network_offering_details__name` (`name`);
|
||||
|
||||
ALTER TABLE `cloud`.`resource_tags` ADD INDEX `i_resource_tags__resource_id__resource_type` (`resource_id`, `resource_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 `cloud`.`storage_pool` ADD INDEX `i_storage_pool__data_center_id_status_scope_hypervisor` (`data_center_id`, `status`, `scope`, `hypervisor`);
|
||||
|
||||
ALTER TABLE `cloud`.`router_network_ref` ADD INDEX `i_router_network_ref__guest_type` (`guest_type`);
|
||||
|
||||
ALTER TABLE `cloud`.`domain_router` ADD INDEX `i_domain_router__role` (`role`);
|
||||
|
||||
ALTER TABLE `cloud`.`async_job` ADD INDEX `i_async_job__instance_type_job_status` (`instance_type`, `job_status`);
|
||||
|
||||
ALTER TABLE `cloud`.`cluster` ADD INDEX `i_cluster__managed_state` (`managed_state`);
|
||||
|
||||
-- speeds up user_vm_view (listVM) queries by forcing index on user_ip_address table
|
||||
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
|
||||
CREATE VIEW `user_vm_view` AS
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user