0

I have this query :

SELECT some_15_fields,

(SELECT GROUP_CONCAT(tb_inv_private_ip SEPARATOR ', ') FROM `network_interface`
WHERE network_interface.tb_inv_id=id) as 'private_ip',

(SELECT GROUP_CONCAT(server_inv_public_ip.tb_public_ip_address SEPARATOR ', ')
FROM server_inv_public_ip JOIN network_interface on server_inv_public_ip_id=network_interface.tb_inv_public_ip_id
WHERE network_interface.tb_inv_id=id) AS 'public_ip'

FROM inventory

LEFT JOIN portal_credential ON inventory.portal_tbl_id = portal_credential.id
LEFT JOIN customer_customer ON inventory.customer_tbl_id = customer_customer.id 

WHERE

server_inventory.customer_tbl_id = '{cust_id}' AND inventory.active_flag in {state}

LIMIT 0, 1000;

My Django app on my server which has MySQL 8 too is returning

Error Code: 2013. Lost connection to MySQL server during query

I had to change LIMIT 0, 1000 to LIMIT 0, 500 for it to return the results;

How can I fix this ?

(Using raw query in Django and not using ORM here)

2
  • Updated original post - I had the query copied from the python code editing the table names text .
    – anjanesh
    Commented Jun 5 at 7:17
  • 1) Your subqueries in the output list are executed for each separate output line, I think. Try to move them from the output list to FROM clause. 2) What is total rows amount for your query? When you specify LIMIT then MySQL retrieves all output lines and finally returns the specified amount of them. I think that finally step is those one where these subqueries are execited, and this process needs in muct time which results in the observed timeout. 3) LIMIT without ORDER BY is strange... Do you really not care which output rows you get?
    – Akina
    Commented Jun 5 at 7:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.