Md Hasibur Rahaman
Md Hasibur Rahaman

Reputation: 1061

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 ?

Upvotes: 1

Views: 74

Answers (3)

Conrado Peria
Conrado Peria

Reputation: 1

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

Upvotes: 0

Krishna Rani Sahoo
Krishna Rani Sahoo

Reputation: 1539

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.

Upvotes: 1

Adesh Pandey
Adesh Pandey

Reputation: 769

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.

Upvotes: 0

Related Questions