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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:13:35+00:00 2026-05-15T15:13:35+00:00

Say for example I have a table like this, with a primary key on

  • 0

Say for example I have a table like this, with a primary key on the first 3 fields:

itemid | type | value | other_field [etc]

If on my web pages I am nearly always selecting by the type field only, it is worth having a separate index on type (i.e. will performance improve), or does the primary key index cover the field anyway?

  • 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-05-15T15:13:36+00:00Added an answer on May 15, 2026 at 3:13 pm

    The order of the fields in an index / key matters.

    If your primary key is on (type, itemid, value) or (type, value, itemid) then an extra index will probably make little difference. An index on multiple columns can also be used on any complete prefix of that index. One advantage of creating a new index in this situation is that is slightly narrower so there will be more rows on each page, but this difference will probably be small. Also you should consider the benefits for queries against the extra cost for modifications to your data.

    If your primary key is anything else, such as (itemid, type, value) then an extra index on (type) will probably help because the primary key cannot be used as an index on type when type is not first in the list.

    The usual remarks about premature optimization also hold here. The best way to be sure what is fastest is to test it yourself on realistic data. There are some conditions where an index will not be used even if you think it should be, or other times when it uses an index other than the one you thought it would. If you want to improve the performance of your application you should collect (or randomly generate if that is not an option) some realistic quantity of data and measure the actual performance of your queries on this data with the different indexing strategies.

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

Sidebar

Related Questions

Let's say I have a table like this (this is just a simplified example,
Say you have a table like this: ID | Type | Reference #1 |
I have an NSDictionary that we will say is like this: key: value: name
First time post. As an example, say I have a table with 12 entries;
say for example i have 2 div in a div like this <div style=width:
If I have a table like this very very simple example: table { table-layout:fixed;
Let's say I have table with column 'URL' whrere I store urls like this
Let us say I have a table called animals that looks like this: 1
Say we have a table like this: **tablename** ID Name Size Date AtStore1 AtStore2
For example, say I have a table with 10 columns in it, but I

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.