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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:11:38+00:00 2026-06-10T19:11:38+00:00

Imagine that we have a query like this: select a.col1, b.col2 from t1 a

  • 0

Imagine that we have a query like this:

select a.col1, b.col2
from t1 a
inner join t2 b on a.col1 = b.col2
where a.col1 = 'abc'

Both col1 and col2 don’t have any index.


If I add another restriction on the where clause, one that is always correct but with a column with an index:

select a.col1, b.col2
from t1 a
inner join t2 b on a.col1 = b.col2
where a.col1 = 'abc'
and a.id >= 0  -- column always true and with index

May the query perform faster since it may use the index on id column?

  • 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-10T19:11:39+00:00Added an answer on June 10, 2026 at 7:11 pm

    Use the index on id to do what?

    The most costly bit here is the join on the join columns, and id has nothing to do with that.

    Most likely scenario, it makes no difference.

    Possible outcome: It makes it take more, because it doesn’t work out that id is always greater than zero, so it makes an index scan to find the correct rows, and then from that obtains the same rows it would have gotten from an table-scan (it would be different perhaps if there was a INCLUDE covering the columns in question).

    Outlandish outcome: Well, stranger things have happened in the world of database optimisation, so I wouldn’t eat my hat if it helped, but I’d still be mightily surprised.

    Really though, forcing irrelevant work with irrelevant indices is not going to help your cause.

    Edit: Actually I thought of a case where it can help. SQLServer will generally use some index to seek upon, in the absence of a directly relevant one, because seek generally does better than scan even in that case. Forcing a seek upon a different index could just feasibly improve things, if for some reason that seek was better and for some reason it picked a different one to seek on. I’d still be pretty surprised though.

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

Sidebar

Related Questions

Imagine that you have 2 tables like this: mysql> SELECT * FROM theme; +----+---------+------------+
Imagine that you have a column with a bunch of fields like this: ab
I have this postgres sql query: select * from stats where athlete_id = 5
Imagine I have the following SQL query: SELECT id,name FROM user WHERE id IN
Imagine I have some XML that looks like this: DECLARE @xml XML SET @xml
I would like to ask you: Imagine that you have a site and there
I have a query that can be summarised in SQL as follows; Select S.StockCode
I have a query: (using a very simple example) SELECT ItemCategory, ItemID, Sales FROM
I've got a query that presently looks something like this (I'll simplify it to
I have SQL data that looks like this: events id name capacity 1 Cooking

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.