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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:26:53+00:00 2026-06-15T23:26:53+00:00

I’m having trouble with huge datasets in mysql and I’m exploring lots of different

  • 0

I’m having trouble with huge datasets in mysql and I’m exploring lots of different ways to index. Can anyone tell me what the difference is if I declare several indexes together

ALTER TABLE `db`.`test` ADD INDEX `someindex` (field1, field2, field3);

Rather than declaring them separately?

ALTER TABLE `db`.`test` ADD INDEX `f1` (field1), ADD INDEX `f2` (field2);

Why would one want to declare them together or separately?

  • 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-15T23:26:55+00:00Added an answer on June 15, 2026 at 11:26 pm

    I teach MySQL training classes, and when discussing multi-column indexes, I use an analogy to a telephone book. A telephone book is basically an index on last name, then first name. So the sort order is determined by which “column” is first. Searches fall into a few categories:

    1. If you look up people whose last name is Smith, you can find them easily because the book is sorted by last name.
    2. If you look up people whose first name is John, the telephone book doesn’t help because the Johns are scattered throughout the book. You have to scan the whole telephone book to find them all.
    3. If you look up people with a specific last name Smith and a specific first name John, the book helps because you find the Smiths sorted together, and within that group of Smiths, the Johns are also found in sorted order.

    If you had a telephone book sorted by first name then by last name, the sorting of the book would assist you in the above cases #2 and #3, but not case #1.

    That explains cases for looking up exact values, but what if you’re looking up by ranges of values? Say you wanted to find all people whose first name is John and whose last name begins with ‘S’ (Smith, Saunders, Staunton, Sherman, etc.). The Johns are sorted under J within each last name, but if you want all Johns for all last names starting with S, the Johns are not grouped together. They’re scattered again, so you end up having to scan through all the names with last name starting with ‘S’. Whereas if the telephone book were organized by first name then by last name, you’d find all the Johns together, then within the Johns, all the S last names would be grouped together.

    So the order of columns in a multi-column index definitely matters. One type of query may need a certain column order for the index. If you have several types of queries, you might need several indexes to help them, with columns in different orders.

    For more details and examples, see my presentation How to Design Indexes, Really. Or watch my presentation on video.


    To clarify when to use a single-column index vs. a multi-column index, consider if you are using your phone book to look up a person by the combination of last name and first name. For example “Sarah Smith.”

    If you had two phone books, one organized by last name and the other organized by first name, you could search the last name book for “Smith” and search the first name book for “Sarah” and then somehow find the intersection of the two results. MySQL sometimes tries to do this with the index merge algorithm.

    It would be better to search one index, if it’s sorted by both last name and first name, like a real phone book. Then the search finds the subset of the book for “Smiths” and within that subset, it can efficiently search for “Sarahs” because the subset is sorted by first name.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've tracked down a weird MySQL problem to the two different ways I was
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.