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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:02:37+00:00 2026-06-04T16:02:37+00:00

I have a very large table (millions of records) containing approximately 8 fields as

  • 0

I have a very large table (millions of records) containing approximately 8 fields as a primary key. for simplicities sake lets say that the table looks like this:

    key_1 | key_2 | key_3 | ... | key_8 | value

given a value for key_1, I need to fetch all possible values for key_2, key_3, …, key_8
something along the following lines:

    SELECT DISTINCT key_2 FROM table1 WHERE key_1 = 123;
    SELECT DISTINCT key_3 FROM table1 WHERE key_1 = 123;
    ...
    SELECT DISTINCT key_8 FROM table1 WHERE key_1 = 123;

My problem is that this query is significantly slower then my performance needs, and the data in this table is fairly constant and rarely updated(once every few days). Also table_1 could be a slow sub-query. Short of creating an additional table in the database and manually updating it every time the database is updated, is there another solution that can give me fast results. I would need it to work across multiple MySQL Sessions.

  • 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-04T16:02:39+00:00Added an answer on June 4, 2026 at 4:02 pm

    Can’t give a definitive answer with the information we have, but let’s start with these:

    Do you have an index on key_1?

    Without it, each query by itself will already be slow just looking for 123.

    Do you have an index on (key_1, key_2)?

    Because select distinct key_2 where key_1 = 123 is really fast if it can get all the necessary data from the index alone. No need to access the table.

    Are the rows/indexes fixed-size?

    Traversing a fixed-size table/row can be faster because one always knows where the x-th record is by just calculating the offset. Variable row sized tables are slower.

    Have you tried adding an autoincrement surrogate primary key?

    Indexes work way better when all they have to store is the column, and a small primary key. Composite primary keys are slower.

    Did you consider a read-only table?

    You can pack myisam table for fast access, but they become read-only. It’s a hack that has its uses though.

    One step further, have you considered a datawarehouse?

    If the tables don’t change often, it might be best to duplicate the information for fast access.

    Can you post a show create table statement? Seeing the columns and indexes would help.
    Can you post an explain select statement? Seeing which indexes are used would help.

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

Sidebar

Related Questions

I have a very large table with a primary key of BINARY(20) . The
I have a very large database with about 120 Million records in one table.I
I have a very large table being filled with about 100s of million records
I have a very large table (few million records). The columns in the table
I have a very large dataset - millions of records - that I want
I have a relatively large table (a couple millions of records), multiple websites are
I have a very large (millions of rows) SQL table which represents name-value pairs
I have a large table (60+) millions of records. I'm using PHP script to
I have a very large table (more than 10M or even 100M records) with
I have a very large table of over 9 million rows and in my

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.