Why is my MySQL connecting slowly?

I have one query that joins tables. This is the select statement:

SELECT *, A.id AS id, 
       A.username AS username, 
       G.desc AS customer_desc, 
       H.id AS counter, 
       SUM( F.amount_paid ) 
FROM tblcheckin AS A
LEFT OUTER JOIN tblrate AS B ON B.id = A.rate_id
LEFT OUTER JOIN tblrefaccom_type AS C ON C.id = A.id
LEFT OUTER JOIN tblcust_bill AS D ON D.check_in_id = A.id
LEFT OUTER JOIN tblroom AS E ON E.room_no = A.room_id
LEFT OUTER JOIN tblpayment AS F ON F.check_in_id = A.id
LEFT OUTER JOIN tblrefcust_type AS G ON G.id = A.customer_desc
LEFT OUTER JOIN tblindex AS H ON A.id = H.check_in_id
WHERE A.check_out =  "0000-00-00 00:00:00"
GROUP BY F.check_in_id
ORDER BY check_out, check_in

Result: Showing rows 0 - 11 ( 12 total, Query took 7.4061 sec)

And this Explain SQL

enter image description here

This is mine, which I have done so far: I installed optimizer_search_depth = 0, as I thought it would work, as indicated here Join many tables in mySQL .

What am I doing wrong here? I appreciate the feedback and feedback. Thank.

UPDATE The problem is solved. I added an index to the check_in_id column of tblpayment, tblcust_bill and tblindex. Here's the new one Explain SQL:

enter image description here

+4
source share
2 answers

, , . , A.check_out, D.check_in_id, F.check_in_id ( ) H.check_in_id. , A, D, F H .

4 , .

, , , . - (, - / ), 7 . , 70 , . , mysql - , .. .

+3

, , , . , ?

SELECT A.id AS id, 
       A.username AS username, 
       G.desc AS customer_desc, 
       H.id AS counter, 
       SUM( F.amount_paid ) 
FROM tblcheckin AS A
LEFT OUTER JOIN tblpayment AS F ON F.check_in_id = A.id
LEFT OUTER JOIN tblrefcust_type AS G ON G.id = A.customer_desc
LEFT OUTER JOIN tblindex AS H ON A.id = H.check_in_id
WHERE A.check_out =  "0000-00-00 00:00:00"
GROUP BY F.check_in_id
ORDER BY check_out, check_in

MySQL hackstension GROUP BY. .

GROUP BY A.id, A.username, G.desc, H.id

tblcheckin ? , , check_out NOT NULL.

, , ON JOIN, :

   tblpayment.check_in_id
   tblrefcust_type.id   (maybe already a primary key)
   tblindex.check_in_id

( ). , , , , . .

   tblcheckin (cneck_out, id, customer_desc, username)
   tblpayment  (check_in_id, amount_paid)
   tblrefcust_type  (id, desc)
   tblindex        (check_in_id, id)
+2

Source: https://habr.com/ru/post/1531687/


All Articles