Home » Performance » MySQL » Optimizing ORDER BY - Returned data is not in the expected order
Optimizing ORDER BY - Returned data is not in the expected order [message #2658] Thu, 21 February 2008 07:18 Go to previous message
arthurica  is currently offline arthurica
Messages: 7
Registered: January 2008
Junior Member
I have a weird problem... I have a very large table with products and I am trying to optimize some queries for retrieving data from this table

I run this query on the table

ALTER TABLE prod ORDER BY prod_rank DESC;

So when I retrieve data I expect to have the records sorted by prod_rank descending... This is happening for most of categories BUT not for few ones when data appears to by arranged randomly

I have tried it with 2 differnet indexes and the results are about the same

1. index RANK (fk_cat, prod_rank DESC)
2. index fk_cat (fk_cat)

So for example this query will return the results sorted just fine

select prod_key, prod_rank from products
where fk_cat = 100
limit 1000

but this one will not

select prod_key, prod_rank from products
where fk_cat = 250
limit 1000

This appears to be randomly as far as the category ID

Am I doing something wrong or am I missing somthine obviously?

Read Message
Read Message
Previous Topic:Slow query - Using where; Using temporary; Using filesort
Next Topic:Merge table Vs Big Table
Goto Forum:

  


Current Time: Fri Jul 10 00:45:45 EDT 2009

Total time taken to generate the page: 0.00847 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.