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 8834111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:56:20+00:00 2026-06-14T08:56:20+00:00

I have a large table stored in mysql (basically, a log) that looks like

  • 0

I have a large table stored in mysql (basically, a log) that looks like this:

  CREATE TABLE `log` (
    `ID_1` int(10) unsigned NOT NULL,
    `ID_2` int(10) unsigned NOT NULL,
    `DELTA` tinyint(3) unsigned NOT NULL,
    `ACTIVE` tinyint(1) NOT NULL,
    `DATA` bigint(20) unsigned NOT NULL,
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8$$

No index. Data is inserted at random moments with random data and it work fine. Then, the table is taken offline (no read/write operations on it). The table size in this moment is around 180M records. I am adding an index on ID_1, ID_2, DELTA, ACTIVE fields (all 4, ascending). It works fairly fast (3-4 minutes).

Now, I am trying to get all the data from the table in ascending order by ID_1, ID_2, DELTA, ACTIVE (same fields and in the same order as in index) but the select stays for ages in ‘SORTING RESULT’ (in SHOW PROCESSLIST) until first row is returned. I tried to hint/force the SELECT statement to use the index (i.e. FORCE INDEX / USE INDEX) but there isn’t any difference. Any hint on how can I increase the response speed of this kind of query:

SELECT `ID_1`, `ID_2`, `DELTA`, `ACTIVE` FROM `log` ORDER BY `ID_1`, `ID_2`, `DELTA`, `ACTIVE` ASC;

?

A similar question has been asked here: Slow ORDER BY in large table – but without an answer. Thought it’s a good idea to post one like it, maybe someone knows the answer by now.

Thank you!

  • 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-06-14T08:56:21+00:00Added an answer on June 14, 2026 at 8:56 am

    To efficiently sort the data, you must add a compound index using all the columns you want to use in the ORDER BY clause. The order of the columns in the index must be the same as the order of the columns in the ORDER BY clause.

    In your case, it would be:

    ALTER TABLE `log` ADD INDEX mySortIndex(`ID_1`, `ID_2`, `DELTA`, `ACTIVE`);
    

    To check how MySQL is executing your query, use:

    EXPLAIN SELECT `ID_1`, `ID_2`, `DELTA`, `ACTIVE` FROM `log` ORDER BY `ID_1`, `ID_2`, `DELTA`, `ACTIVE` ASC;
    

    The output will tell you which indexes are used.

    If you are only going to need a known number of result rows, you may use LIMIT to prevent MySQL from sorting the entire table:

    SELECT `ID_1`, `ID_2`, `DELTA`, `ACTIVE`
    FROM `log` ORDER BY `ID_1`, `ID_2`, `DELTA`, `ACTIVE` ASC
    LIMIT 100;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a very large (10million+) row table stored in MySql using the InnoDB
We have a large table that services many different stored procedures on lots of
I have a large mysql table with parent-child relationships stored in the nested set
I have a large table of data (that displays test data) that is separated
I have a large table (~1M rows now, soon ~10M) that has two ranked
If I have large articles that need to be stored in a database, each
I am generating a table in HTML from a MySQL database, so that stored
I have a large table and I'd like to store the results in Memcache.
I have a mysql database table that will store locations for buildings and events
I have a large table of birthdays that I want to convert from a

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.