简体   繁体   中英

Mysql query exicution time is too slow

SELECT * FROM articles t LEFT OUTER JOIN category_type category ON ( t . category_id = category . id ) WHERE (t.status = 6 AND t.publish_on <= '2014-02-14' AND t.id NOT IN (13112,9490,9386,6045,1581,1034,991,933,879,758) AND t.category_id IN (14)) ORDER BY t.id DESC LIMIT 7;

It take more then 1.5 second to execute this query.

Can you give me some idea ? How can I improve this query and minimum execution time ?

First thing => use where instead of inner join . Because where is faster than inner join query.

Second thing => use indexes for the frequently searched columns . As in your example you search on the basis of status, publish_on besides id as primary index .

If you are using mysql then you can try propose table structure option in the phpmyadmin which can help you to decide valid data types for your column names. This could help you to optimize your query processing.

query processing time depends on many things like: database server load, amount of data in the table and the data types used for the column names too.

why join it with category table?, the category table is not in the where clause nor in the select column clause, so why add it in the query?

oops, * was used, so it "is" in the category table

apologies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM