cloud_controller_ng icon indicating copy to clipboard operation
cloud_controller_ng copied to clipboard

Possible slow query

Open colins opened this issue 3 years ago • 3 comments

We (the MySQL team) have received a customer support query about a slow query. The query is taking 18 seconds. JIRA The query is doing a large join.

SELECT count(*) AS `count` FROM (SELECT DISTINCT `service_instances`.* FROM `service_instances` INNER JOIN `spaces` ON (`spaces`.`id` = `service_instances`.`space_id`) LEFT JOIN `service_instance_shares` ON (`service_instance_shares`.`service_instance_guid` = `service_instances`.`guid`)) AS `t1` LIMIT 1;
# Time: 2022-09-01T09:04:11.389209Z
# Schema: ccdb  Last_errno: 0  Killed: 0
# Query_time: 18.541919  Lock_time: 0.000479  Rows_sent: 1  Rows_examined: 144329  Rows_affected: 0  Bytes_sent: 60

This appears to be the corresponding model https://github.com/cloudfoundry/cloud_controller_ng/blob/0645a640be62cef0a524164d15aaf93957ee5458/app/models/services/service_instance.rb#L37

colins avatar Sep 09 '22 18:09 colins

Hi @colins,

What is the CAPI version? Which endpoint is called (what parameters)? Is this the exact SQL query? The LEFT JOIN without WHERE condition does not make sense...

philippthun avatar Sep 12 '22 09:09 philippthun

What is the CAPI version? name: capi version: 1.117.7

Which endpoint is called (what parameters)? mysql_proxy VM.

Is this the exact SQL query? Yes. We only trimmed out the IP addresses from the log lines.

I'm guessing if you run this spec you'll see that query in the rails log https://github.com/cloudfoundry/cloud_controller_ng/blob/5b358a0e69213bfcb24e401f52e6f6339f660c6e/spec/unit/actions/service_instance_share_spec.rb#L13

Here's the JIRA ticket for reference: https://pivotal-io.atlassian.net/browse/MYSQL-74

colins avatar Sep 12 '22 21:09 colins

I ran the mentioned spec file but don't see such an SQL statement in the logs. To reproduce the issue, we would need to know which API endpoint is called (e.g. /v2/service_instances or /v3/service_instances) and which parameters are provided (e.g. space_guids=...). This would allow us to check if the SQL statement looks the same in current CAPI versions or has already been changed; there have been quite some significant performance improvements / query optimizations been taking place in the last year.

philippthun avatar Sep 13 '22 14:09 philippthun