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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:25:40+00:00 2026-06-17T04:25:40+00:00

I have a large MySql table with over 11 million rows. This is just

  • 0

I have a large MySql table with over 11 million rows. This is just a huge data set and my task is to be able to analyze the dataset based on certain rules.

Each row belongs to a certain category. There are 2 million different categories. I want to get all rows for a category and perform operations on that.

So currently, I do the following:

  1. Select distinct categories from the table.
  2. for each category : Select fields from table WHERE category=category

Even though my category column is indexed, it takes a really long time to execute Step 2. This is mainly because of the huge data set.

Alternatively, I can use GROUP BY clause, however I am not sure if it will be as fast since GROUP BY on such a huge dataset may be expensive, especially when considering that I will be running my analysis several times on parts of the dataset. A way to permanently ensure a sorted table would be useful.

Therefore as an alternative, I can speed up my queries if only my table is pre-sorted by category. Now I can just read the table row by row and perform the same operations in a much faster time, as all rows of one category will be fetched consecutively.

As the dataset (MySql table) is fixed and no update, delete, insert operations will be performed on it. I want to be able to ensure a way to maintain a default sort order by category. Can anyone suggest a trick to ensure the default sort order of the rows.

Maybe read all rows and rewrite them to a new table or add a new primary key which ensures this order?

  • 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-17T04:25:42+00:00Added an answer on June 17, 2026 at 4:25 am

    Even though my category column is indexed

    Indexed by a secondary index? If so, you can encounter the following performance problems:

    • InnoDB tables are always clustered and the secondary index in clustered table can require a double-lookup (see the “Disadvantages of clustering” in this article).
    • Indexed rows can be scattered all over the place (index can have bad clustering factor – the link is for Oracle but the principle is the same). If so, an index range scan (such as WHERE category = whatever) can end-up loading many table pages, even though the index is actually used and only a small subset of rows is actually selected. This can destroy the range scan performance.

    In alternative to the secondary index, consider using a natural primary key, which in InnoDB tables also acts as a clustering key. The primary/clustering key such as {category, no} will keep the rows of the same category physically close together, making both of your queries (and especially the second one) maximally efficient.

    OTOH, if you want to keep the secondary index, consider covering all the fields that you query, so the primary B-Tree doesn’t have to be touched at all.

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

Sidebar

Related Questions

I have a large MySQL table (about 750 million rows) and I just want
I have a very large MySql table: over 900 rows of different sentences. I
I have a large mysql MyISAM table with 1.5mil rows and 4.5GB big, still
I have a large mysql table (about 5M rows) on which i frequently insert
I have a large mysql table with parent-child relationships stored in the nested set
I have a very large MySQL table (billions of rows, with dozens of columns)
I have a large table in mysql, about 1 million records. I'm using a
I have a large MySQL table which looks like this: job_number time_on time_off 111
i have a large mysql database table in which one column contains values ranging
I have a MySQL database with a fairly large table where the products are.

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.