0

Possible Duplicate:
Slow query performance

My database contains 20,000 rows and the following query is slow. Please help me to speed this up.

SELECT r.report_id, r.user_id,u.user_name,u.user_mail,
  d.department_name,r.report_comment, r.report_target_date,r.report_create_date,
  r.report_revised_date,r.report_root_id
FROM report r FORCE INDEX (unique_report)
JOIN `user` u 
  ON u.user_id = r.user_id
JOIN department d  FORCE INDEX (unique_department) 
  ON u.department_id = d.department_id
WHERE (u.user_name LIKE CONCAT('%', 'hieu', '%')) 
  AND (d.department_name LIKE CONCAT('%', 'BOM', '%')) 
  AND r.report_id IN (
            SELECT r.report_id
            FROM report r FORCE INDEX (unique_report)
            WHERE r.user_id =1 
            UNION ALL
            SELECT r.report_id
            FROM report r
            JOIN `user` u 
              ON u.user_id = r.user_id
            JOIN department d FORCE INDEX (unique_department) 
              ON u.department_id = d.department_id
            JOIN authority a FORCE INDEX (unique_authority) 
              ON r.user_id = a.user_src_id
            WHERE a.user_dest_id =1) 
              AND (r.report_id IN (
                    SELECT r.report_id
                    FROM report r FORCE INDEX (unique_report)
                    WHERE r.report_comment LIKE CONCAT('%', 'this', '%')) 
                       OR r.report_id IN (
                          SELECT report_id 
                          FROM report_content FORCE INDEX (unique_report_content) 
                          WHERE visited_company LIKE CONCAT('%', 'this', '%')
                          UNION
                          SELECT report_id 
                          FROM report_content FORCE INDEX (unique_report_content) 
                          WHERE report_description LIKE CONCAT('%', 'this', '%')))
ORDER BY r.report_target_date DESC
LIMIT 0, 30
  • Please edit your question with a query plan. – Philᵀᴹ Jan 30 '13 at 11:23
  • Firstly, between 'please' and 'pls' the difference is only 3 letters. I'll give them to you free of charge. (Read: please, post well-formed questions only if you want to be polite to others.) Otherwise there are missing information: table structure (including indexes), execution plan and time, RDBMS and so on. – András Váczi Jan 30 '13 at 11:26
  • 3
    Isn't this the exact same query that you posted here? http://dba.stackexchange.com/questions/33828/help-my-optimize-this-mysql-query – Taryn Jan 30 '13 at 11:34
  • 1
    Voted to close as "exact duplicate". – ypercubeᵀᴹ Jan 30 '13 at 11:50

0 Answers0