Skip to content

Commit a0be5c8

Browse files
mprokopchuksb-abhish3k
authored andcommitted
Added performance indexes
1 parent 1ceb1d0 commit a0be5c8

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,33 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_schedule', 'isolated', 'TINYI
646646

647647
UPDATE `cloud`.`configuration` SET `value`=CONCAT(`value`, ', backupValidationCommandTimeout, backupValidationScreenshotWait, backupValidationBootTimeout')
648648
WHERE `name`='user.vm.readonly.details' AND `value` IS NOT NULL;
649+
650+
-- Composite index on nics(instance_id, removed) to fix wrong-index pick in user_vm_view.
651+
-- The optimizer picks i_nics__removed over fk_nics__instance_id for the
652+
-- LEFT JOIN nics ON (vm_instance.id = nics.instance_id AND nics.removed IS NULL)
653+
-- because neither single-column index covers both predicates.
654+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_nics__instance_id_removed', 'cloud.nics', '(instance_id, removed)');
655+
-- account_view performance: covers all 10 resource_limit LEFT JOINs
656+
-- which filter on (account_id = ? AND type = ? AND tag IS NULL)
657+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_resource_limit__acct_type_tag', 'cloud.resource_limit', '(account_id, type, tag)');
658+
-- account_vmstats_view: enables index-only scan for GROUP BY account_id, state
659+
-- WHERE vm_type = 'User' AND removed IS NULL
660+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_vm_instance__account_id_state', 'cloud.vm_instance', '(account_id, state)');
661+
-- free_ip_view: covers WHERE state = 'Free' JOIN vlan ON vlan.id = vlan_db_id
662+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_user_ip_address__state_vlan', 'cloud.user_ip_address', '(state, vlan_db_id)');
663+
-- Prometheus/AlertManager IP count queries: covers WHERE data_center_id = ? AND removed IS NULL
664+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_user_ip_address__dc_removed_vlan', 'cloud.user_ip_address', '(data_center_id, removed, vlan_db_id)');
665+
-- event table: compound index for frequent Compute API queries
666+
-- (WHERE archived = 0 AND level = ? ORDER BY created)
667+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__archived_level_created', 'cloud.event', '(archived, level, created)');
668+
-- event table: default listEvents path (account + archived + sort)
669+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__account_archived_created', 'cloud.event', '(account_id, archived, created DESC)');
670+
-- event table: domain-scoped ACL queries (completely unindexed)
671+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__domain_id', 'cloud.event', '(domain_id)');
672+
-- event table: resource-based event lookups (added in 4.16.1 with no index)
673+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__resource', 'cloud.event', '(resource_id, resource_type)');
674+
-- event table: start_id for related-event queries and event_view self-join
675+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__start_id', 'cloud.event', '(start_id)');
676+
-- host table: covers findByName lookups (WHERE name = ? AND removed IS NULL)
677+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_host__name_removed', 'cloud.host', '(name, removed)');
678+

0 commit comments

Comments
 (0)