Bluehost.com Web Hosting $6.95

Query optimization suggestions

This is a discussion on Query optimization suggestions within the MySQL Database forums, part of the Database Forums category; Hi all, I have a table like that: articles { cat INT(10) UNSIGNED id INT(10) UNSIGNED aorder INT(10) ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-08-2006
howa
 
Posts: n/a
Default Query optimization suggestions

Hi all,

I have a table like that:


articles {

cat INT(10) UNSIGNED
id INT(10) UNSIGNED
aorder INT(10) UNSIGNED
lastupdated INT(10) UNSIGNED
}


I want to query something like:

SELECT * FROM articles
WHERE cat = 9 AND aorder >= 0
ORDER BY aorder DESC, lastupdated DESC
LIMIT 13095, 10

the query is quite slow when number of records in the articles say,
more than 1M row

currently, index = (cat, aorder, lastupdated)

any suggestion to improve or re-design the table?

thanks.

Reply With Quote
  #2 (permalink)  
Old 12-08-2006
Captain Paralytic
 
Posts: n/a
Default Re: Query optimization suggestions


howa wrote:
> Hi all,
>
> I have a table like that:
>
>
> articles {
>
> cat INT(10) UNSIGNED
> id INT(10) UNSIGNED
> aorder INT(10) UNSIGNED
> lastupdated INT(10) UNSIGNED
> }
>
>
> I want to query something like:
>
> SELECT * FROM articles
> WHERE cat = 9 AND aorder >= 0
> ORDER BY aorder DESC, lastupdated DESC
> LIMIT 13095, 10
>
> the query is quite slow when number of records in the articles say,
> more than 1M row
>
> currently, index = (cat, aorder, lastupdated)
>
> any suggestion to improve or re-design the table?
>
> thanks.

Does an explain say that the index is being used for the sort?

If not try ORDER BY cat DESC, aorder DESC, lastupdated DESC; in order
(no pun intended) to help the optimiser to realise what it should be
doing.

Reply With Quote
  #3 (permalink)  
Old 12-08-2006
howa
 
Posts: n/a
Default Re: Query optimization suggestions


Captain Paralytic ¼g¹D¡G

> howa wrote:
> > Hi all,
> >
> > I have a table like that:
> >
> >
> > articles {
> >
> > cat INT(10) UNSIGNED
> > id INT(10) UNSIGNED
> > aorder INT(10) UNSIGNED
> > lastupdated INT(10) UNSIGNED
> > }
> >
> >
> > I want to query something like:
> >
> > SELECT * FROM articles
> > WHERE cat = 9 AND aorder >= 0
> > ORDER BY aorder DESC, lastupdated DESC
> > LIMIT 13095, 10
> >
> > the query is quite slow when number of records in the articles say,
> > more than 1M row
> >
> > currently, index = (cat, aorder, lastupdated)
> >
> > any suggestion to improve or re-design the table?
> >
> > thanks.

> Does an explain say that the index is being used for the sort?
>
> If not try ORDER BY cat DESC, aorder DESC, lastupdated DESC; in order
> (no pun intended) to help the optimiser to realise what it should be
> doing.


the optimizer said the index - (cat, aorder, lastupdated) is being
used, rows involved is around 60K (out of 2M rows) - becasue actually
the number of rows satisifed the conidition is really 60K...

but i only want to take 15 rows out of them (due to paging)

are there anyway to rewrite the query can improve the result?

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:23 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0