Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

How to improve index on multiple columns

$
0
0
Hi,

I have index on multiple columns to get records based on multiple conditions as:

Code:

Explain SELECT title, data, url, direction 
                FROM content
                WHERE
                member_id = 1
                AND year = 2012
                AND month = 11
                AND type='member'
                AND status=1
                order by content_id DESC
                LIMIT 2000, 5

This is the explanation I get:
Code:

        id_home_status,index_id_year_month_type_status        index_id_year_month_type_status        87        const,const,const,const,const        5001        Using where
The indexed columns are (member_id, year, month, type, status), and content_id is the Primary Key.

There are 0.5M+ records in a table, the query is taking around 20 seconds. What changes should I make to get the results faster?

Thanks,

-----------------

I did more experiments and found out that the 'offset' of LIMIT clause is causing all the delay, for example using LIMIT 100, 5 took about 500ms. So, what's the best way of using Limit clause?

Viewing all articles
Browse latest Browse all 13329

Trending Articles