Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    21

    Unanswered: How can I force MySQL to use the index in sorting the records?

    I run the explain command on this select statement and I always get filesort in the results (in the extra column) even though I have an index on the postid column (primary key), although not related but threadid is also indexed by the way:

    explain select * from forumposts where threadid = 5 order by postid;


    How can I force MySQL to use the index in sorting the records? Any suggestions?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    declare an index on (threadid,postid)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2003
    Posts
    21
    Thanks for your reply, actually I thought about this but I don't really want to create another index just for sorting esp. not an index on mutiple columns, I'm worried about the performance of inserts, is there any other solution? I read about FORCE INDEX but I believe it's not used for order by ..

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    remove the index on threadid alone
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •