mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
engine/schema: force index in user_vm_view to speed up VM instance listing (#9198)
The user_vm_view can end up not picking the right index to join against the user_ip_address table causing full table scan on the user_ip_address table. This could be related to a MySQL bug https://bugs.mysql.com/bug.php?id=41220 In a test environment with 20k shared networks and over 20M IPs, the listVirtualMachines API was found to take over 17s to return list of just 10 VMs. However, with this fix it would now take under 200ms to return the list. MySQL slow query logging showed ~nearly 20M table scans of the IP address table: ``` # User@Host: cloud[cloud] @ localhost [127.0.0.1] Id: 39 # Query_time: 8.227541 Lock_time: 0.000014 Rows_sent: 12 Rows_examined: 19,667,235 SET timestamp=1715410270; SELECT user_vm_view.id, user_vm_view.name /*snipped*/ FROM user_vm_view WHERE user_vm_view.id IN (4,6,7,8,9,10,11,12,13,14,15,16); ``` Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
f45267174a
commit
0f8a839a1d
@ -196,7 +196,7 @@ FROM
|
|||||||
LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
|
LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
|
||||||
LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
|
LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
|
||||||
AND ISNULL(`vpc`.`removed`))))
|
AND ISNULL(`vpc`.`removed`))))
|
||||||
LEFT JOIN `user_ip_address` ON ((`user_ip_address`.`vm_id` = `vm_instance`.`id`)))
|
LEFT JOIN `user_ip_address` FORCE INDEX(`fk_user_ip_address__vm_id`) ON ((`user_ip_address`.`vm_id` = `vm_instance`.`id`)))
|
||||||
LEFT JOIN `user_vm_details` `ssh_details` ON (((`ssh_details`.`vm_id` = `vm_instance`.`id`)
|
LEFT JOIN `user_vm_details` `ssh_details` ON (((`ssh_details`.`vm_id` = `vm_instance`.`id`)
|
||||||
AND (`ssh_details`.`name` = 'SSH.KeyPairNames'))))
|
AND (`ssh_details`.`name` = 'SSH.KeyPairNames'))))
|
||||||
LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_instance`.`id`)
|
LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_instance`.`id`)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user