クエリに大きな問題があり、実行に 10 秒以上かかりました
多くのサブクエリと左結合
ここに私のクエリがあります
SELECT tickets.tic_id,
tickets.tic_title,
tic_statue,
tic_priority,
tickets.tic_msg,
customers.cus_name,
employee.emp_name,
count(comments.com_id),
customers.cus_id ,
(
SELECT comments.com_msg
from comments
WHERE tickets.tic_id = comments.tic_id
order by com_id DESC
limit 1
) AS last_comment,
(
SELECT customers.cus_name
from customers INNER JOIN comments on (customers.cus_id = comments.tic_uid)
where comments.com_msg = last_comment
LIMIT 1
)AS by_customer,
(
SELECT employee.emp_name
from employee INNER JOIN comments on (employee.emp_id = comments.tic_emp)
where comments.com_msg = last_comment
LIMIT 1)AS by_employee,
tic_date,
(SELECT comments.com_statue
from comments
WHERE tickets.tic_id = comments.tic_id
order by com_id DESC
limit 1)
AS last_comment_color
FROM tickets
LEFT JOIN employee
on (tickets.tic_emp = employee.emp_id)
LEFT JOIN customers
on (tickets.tic_cus = customers.cus_id)
LEFT join cats
on (tickets.tic_cat = cats.cat_id)
LEFT JOIN comments
on (tickets.tic_id = comments.tic_id)
GROUP by tickets.tic_id
ORDER BY tickets.tic_statue ASC, comments.com_time DESC
limit 50
結果は正常に動作しますが、長い時間
インデックス: ticket.tic_id comments.com_id comments.tic_id customers.cus_id
ありがとうございました :)