Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:05:08+00:00 2026-05-22T18:05:08+00:00

Probably I’m missing some silly thing… Apparently MySQL 5.1 keeps doing a Filesort even

  • 0

Probably I’m missing some silly thing… Apparently MySQL 5.1 keeps doing a Filesort even when there is an index that matches exactly the column in the ORDER BY clause. To post it here, I’ve oversimplified the data model, but the issue is still happening:

Table definition:

CREATE TABLE `event` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `owner_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `owner_id` (`owner_id`),
  KEY `date_created` (`date_created`),
  CONSTRAINT `event_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `user_profile` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

My problem is that event a simple SELECT is showing “Using filesort”:

explain select * from event order by date_created desc;

And the result for the query explain:

id  select_type table   type    possible_keys   key key_len ref rows    Extra   
1   SIMPLE      event   ALL NULL        NULL    NULL    NULL    6       Using filesort

Is there any way for this type of queries to use the index insteas of doing a filesort?

Thanks in advance to everybody.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:05:09+00:00Added an answer on May 22, 2026 at 6:05 pm

    Since your CREATE TABLE statement indicates that you have less than 10 rows (AUTO_INCREMENT=7) and using FORCE INDEX on my installation will make MySQL use the index, I’m guessing the optimizer thinks a table scan is faster (less random I/O) than an index scan (since you’re selecting all columns, not just date_created). This is confirmed by the following:

    mysql> explain select date_created from event order by date_created;
    +----+-------------+-------+-------+---------------+--------------+---------+------+------+-------------+
    | id | select_type | table | type  | possible_keys | key          | key_len | ref  | rows | Extra       |
    +----+-------------+-------+-------+---------------+--------------+---------+------+------+-------------+
    |  1 | SIMPLE      | event | index | NULL          | date_created | 9       | NULL |    1 | Using index |
    +----+-------------+-------+-------+---------------+--------------+---------+------+------+-------------+
    1 row in set (0.00 sec)
    

    In the above case, the index scan is faster because only the indexed column needs to be returned.

    The MySQL documentation has some cases where using an index is considered slower: http://dev.mysql.com/doc/refman/5.1/en/how-to-avoid-table-scan.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a simple thing to fix, but for some reason the content column on
Probably an easy one: Are there any rules of thumb or pointers that could
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
Probably something stupid I'm doing. I want to populate a hidden DIV with values
probably the answer is quite silly but I need a pair fresh of eyes
Probably I'm doing something wrong but here it goes: I'm trying to create a
Probably simple question and I'm just missing something, but I'm stuck out of ideas.
probably a trivially easy thing to do... In C# you can introduce a block
probably there are a lot of people who will smile reading this question... Here's
Probably a silly question here but I have been trying to find this for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.