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

  • Home
  • SEARCH
  • 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 5952651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:42:41+00:00 2026-05-22T17:42:41+00:00

Should I include col3 & col4 in my index on MyTable if this is

  • 0

Should I include col3 & col4 in my index on MyTable if this is the only query I intend to run on my database?

Select MyTable.col3, MyTable.col4
From MyTable 
Inner Join MyOtherTable
On MyTable.col1 = MyOtherTable.col1
And MyTable.col2 = MyOtherTable.col2;

The tables I’m using have about half a million rows in them. For the purposes of my question, col1 & col2 are a unique set found in both tables.

Here’s the example table definition if you really need to know:

CREATE TABLE MyTable 
(col1 varchar(10), col2 varchar(10), col3 varchar(10), col4 varchar(10));

CREATE TABLE MyOtherTable 
(col1 varchar(10), col2 varchar(10));

So, should it be this?

   CREATE MyIdx ON MyTable (col1,col2);

Or this?

   CREATE MyIdx ON MyTable (col1,col2,col3,col4);
  • 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-22T17:42:42+00:00Added an answer on May 22, 2026 at 5:42 pm

    adding columns col3 and col4 will not help because you’re just pulling those values after finding them using columns col1 and col2. The speed would normally come from making sure columns col1 and col2 are indexed.

    You should actually split those indexes since you’re not using them together:

    CREATE MyIdx ON MyTable (col1);
    CREATE MyIdx ON MyTable (col2);

    I don’t think a combined index will help you in this case.

    CORRECTION: I think I’ve misspoken, since you intend to use only that query on the two tables and never have the individual columns joined in isolation. In your case it appears you could get some speed up by putting them together. It would be interesting to benchmark this to see just how much of a speedup you’d see on 1/2 million rows using a combined index versus individual ones. (You should still not use columns col3 and col4 in the index, since you’re not joining anything by them.)

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

Sidebar

Related Questions

From what I understand, the output from the following script should include Win32_PerfRawData_PerfDisk_PhysicalDisk in
Should I be careful adding too many include columns to a non-cluster index? I
What Ruby on Rails gems are available to graph data? This should include the
i need to specify following in one query: It should include the Activity_name and
i need to specify following in one query: It should include the Activity_name and
Sorry, this looks longer than it probably is but I thought I should include
I use the following PHP script as index for my website. This script should
I've been told that I should include PAD files with the freeware applications I
I would like to know when I should include external scripts or write them
I'm trying to implement PayPal Adaptive Payments API. Into the headers I should include

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.