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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:25:37+00:00 2026-06-03T21:25:37+00:00

(This is in a Rails app) Given two tables: items id, int(11), primary key

  • 0

(This is in a Rails app)

Given two tables:

items
id, int(11), primary key
name, varchar(30)

choices
id, int(11), primary key
item_id, int(11), foreign key
identifier, varchar(5)
name, varchar(30)

The majority of queries against choices would be along the lines of:

SELECT identifier, name FROM choices WHERE item_id = n ORDER BY identifier;

Let’s assume that we all agree that an index can help sorting performance (I know we all don’t, that’s okay, but for this question let’s assume).

What is the best way to index choices so as to get both searching and sorting benefits:

  • two indices, one on each of item_id and identifier

or

  • one index on item_id, identifier
  • 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-03T21:25:38+00:00Added an answer on June 3, 2026 at 9:25 pm

    You want the composite index. With the 2 separate indexes mysql would have to choose between using an index for filtering or an index for sorting (since MySQL only uses one index per table in a query). More on how MySQL uses indexes when sorting (your case is one of the examples they give).

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

Sidebar

Related Questions

I ran into this issue while testing a rails app deployed to two different
I have a Rails 2.3.11 app which has two key Models: Activity Transaction Live
My simplified rails app looks like this # chapter.rb has_many :sections has_many :videos, through:
When creating new Rails app I get this error <internal:lib/rubygems/custom_require>:29:in `require': libcrypto.so.0.9.8: cannot open
I am creating a rails app and have used this code in one of
So I have a Rails app (which in this case seems like it would
I'm following this railscast to get elasticsearch going in my rails app. When I
In a controller in my Rails app, I can do this: before_filter :login_required, :except
This is more a general question but my particular case involves a ruby/rails app
So I need to access this service from my rails app. I'm using soap4r

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.