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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:33:30+00:00 2026-06-01T12:33:30+00:00

I am working on optimizing a query which is used very frequently on our

  • 0

I am working on optimizing a query which is used very frequently on our system. The where clause is similar to

WHERE J.Visibility > 11 
and J.isactive='true' 
and J.isdeleted='false' 
AND (
       CutOffDate > '2012-04-05 00:00:00.000' 
       OR J.CreatedOn > '2011-10-08 00:00:00.000'
    ) 
AND J.Country = 'India' 
AND J.City='Bangalore' 
AND (J.Type > 0 AND J.Type < 230)  
AND J.Category in (20)

Already a NC index(Index1) with City, Type, Visibility, IsActive, IsDeleted existed. I created a new NC index with the above fields but adding CreatedOn, CutOffDate and Category in the beginning as well.

So the keys on new Index (Index2) were City, Category, CreatedOn, CutOffDate, Type, Visibility etc. CreatedOn and CutOffDate were both in descending order. However when I ran the query, the actual execution plan still did an Index Scan of the Index1 rather than Index2. Given the DateTime conditions I would have thought Index2 would be the better choice and would result in Index seek. But that did not happen.

While investigating why this could be happening, I came across this MS article and now I am wondering if indexes with datetime need to be created like mentioned in the article. I did not find this technique of creating indexes with datetime mentioned anywhere else when I searched on Google, thus wondering what do others do?

  • 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-01T12:33:32+00:00Added an answer on June 1, 2026 at 12:33 pm

    What is the exact index definition? An index on (City, Category, CreatedOn, CutOffDate, Type, Visibility) cannot be used for your query. In fact, given that you have a criteria that uses an inequality comparison (>) on two fields and and OR condition between them there is no index that could possibly help with the datetime part of the comparison. The article you link has absolutely no relevance for your problem.

    For us to propose a good index you would have to tell us exactly the definition of the table, the exact query you use and the cardinality (number of distinct values) in each column.

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

Sidebar

Related Questions

I am working on optimizing a SQL query that goes against a very wide
I’m working on optimizing some of my queries and I have a query that
I am working on a project involving optimizing energy consumption within a system. Part
I've been working on optimizing a query and have ran into a situation that's
I'm student working on optimizing GCC for multi-core processor. I tried going through the
Working on a page with multiple sections. at the very top there is a
Working on my first Rails project, I used Ryan Bates' Nifty-Generators to create the
This query was working fine when the database was small, but now that there
I am working on optimizing site load speed for a few moderately high traffic
I'm working on optimizing an application . I found that i need to optimize

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.