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

  • Home
  • SEARCH
  • 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 374037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:21:59+00:00 2026-05-12T14:21:59+00:00

I have a table Cars with datetime (DATE) and bit (PUBLIC). Now i would

  • 0

I have a table Cars with datetime (DATE) and bit (PUBLIC).

Now i would like to take rows ordered by DATE and with PUBLIC = 1 so i use:

select
  c.*
from
  Cars c
WHERE 
   c.PUBLIC = 1
ORDER BY 
   DATE DESC

But unfortunately when I use explain to see what is going on I have this:

1   SIMPLE  a   ALL     IDX_PUBLIC,DATE     NULL    NULL    NULL    103     Using where; Using filesort

And it takes 0,3 ms to take this data while I have only 100 rows. Is there any other way to disable filesort?

If i goes to indexes I have index on (PUBLIC, DATE) not unique.

Table def:

CREATE TABLE IF NOT EXISTS `Cars` (
  `ID` int(11) NOT NULL auto_increment,
  `DATE` datetime NOT NULL,
  `PUBLIC` binary(1) NOT NULL default '0'
  PRIMARY KEY  (`ID`),
  KEY `IDX_PUBLIC` (`PUBLIC`),
  KEY `DATE` (`PUBLIC`,`DATE`)
) ENGINE=MyISAM  AUTO_INCREMENT=186 ;
  • 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-12T14:21:59+00:00Added an answer on May 12, 2026 at 2:21 pm

    You need to have a composite index on (public, date)

    This way, MySQL will filter on public and sort on date.

    From your EXPLAIN I see that you don’t have a composite index on (public, date).

    Instead you have two different indexes on public and on date. At least, that’s what their names IDX_PUBLIC and DATE tell.

    Update:

    You public column is not a BIT, it’s a BINARY(1). It’s a character type and uses character comparison.

    When comparing integers to characters, MySQL converts the latter to the former, not vice versa.

    These queries return different results:

    CREATE TABLE t_binary (val BINARY(2) NOT NULL);
    
    INSERT
    INTO    t_binary
    VALUES
    (1),
    (2),
    (3),
    (10);
    
    SELECT  *
    FROM    t_binary
    WHERE   val <= 10;
    
    ---
    1
    2
    3
    10
    
    SELECT  *
    FROM    t_binary
    WHERE   val <= '10';
    ---
    1
    10
    

    Either change your public column to be a bit or rewrite your query as this:

    SELECT  c.*
    FROM    Cars c
    WHERE   c.PUBLIC = '1'
    ORDER BY 
            DATE DESC
    

    , i. e. compare characters with characters, not integers.

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

Sidebar

Related Questions

I have table cars: Id int, Model nvarchar(max), DateOfProduction (datetime). And data like: 1
I have three tables kinda like the example below: TABLE CARS carId carName -----
I have the following table SELECT * FROM cars; id value 1 convertible 2
I have Car (table cars ) method that has_many owners (table owners ). How
i have a table called Cars and the primary key of the table is
i have a table of resources (lets say cars) which i want to claim
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have table with 3 columns A B C. I want to select *

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.