Home » Performance » MySQL » IN(...) ORDER BY ...
IN(...) ORDER BY ... [message #1018] Sun, 01 April 2007 11:40 Go to next message
morpika  is currently offline morpika
Messages: 1
Registered: April 2007
Junior Member
Hi!

I have a very simple table:

CREATE TABLE `users` (
`user_id` MEDIUMINT( 7 ) NOT NULL ,
`user_name` VARCHAR( 30 ) NOT NULL
)

ALTER TABLE `my_users` ADD INDEX ( `user_id` , `user_name` )

I would like to select specified users ordered by their name!

SELECT * FROM `users` WHERE `user_id` IN (1, 2, 3, 11, 22, 33) ORDER BY `user_name`

Unfortunately i can't rid of the filesort Sad
Explain says:

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE my_users range user_id user_id 3 NULL 7 Using where; Using index; Using filesort

I have 18.610 rows in the table:

1. Jane
2. John
3. Smith
ect...



Re: IN(...) ORDER BY ... [message #1022 is a reply to message #1018 ] Tue, 03 April 2007 05:41 Go to previous message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
Don't think there's a way of getting round this as index leafs must be skipped in the second branch (`user_name`) due to using a range in the first.


Martin Gallagher | Speeple: The latest news
Previous Topic:Performance using BETWEEN
Next Topic:MySQL Cluster insert performance.
Goto Forum:
  



Current Time: Tue Jan 6 21:34:09 EST 2009

Total time taken to generate the page: 0.04025 seconds
.:: Contact :: Home :: MySQL Support by Percona.com ::.

Powered by: FUDforum 2.7.5.
Copyright ©2001-2006 FUD Forum Bulletin Board Software

MySQL Performance | Forum authority Badge