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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:27:12+00:00 2026-06-17T20:27:12+00:00

I have a seemingly simple query case where adding a constraint causes a major

  • 0

I have a seemingly simple query case where adding a constraint causes a major performance decrease. The three columns that are being constrained with the AND clause, are all bigints. If I use any two of them (but not all three) the query runs instantaneously, but as soon as I add a third AND, it runs slow.

WITH tb AS (SELECT
   DISTINCT u.*  
FROM
   [user] u  
INNER JOIN
   user_personal up 
      ON up.user_id = u.user_id        
WHERE
   1=1  
   AND u.site_instance_id = 1      
   AND u.graduation_class_id = 27  
   AND u.graduation_term_id IN (76,75) 
   ) SELECT
   COUNT (*) AS count 
FROM
   ( SELECT
      ROW_NUMBER() OVER (
   ORDER BY
      last_name ASC) AS row,
      * 
   FROM
      tb) sub

Does this have to do with the fact that all three of those columns are bigint? Or does it have to do with table indexes on those columns? (I don’t have any indexes set up for those columns). Or could it be something else?

Note – in this case the AND u.site_instance_id = 1 is redundant, but it shouldn’t matter, should it?

EDIT After using SET showplan_all ON:

 |--Compute Scalar(DEFINE:([Expr1005]=CONVERT_IMPLICIT(int,[Expr1008],0)))
   |--Stream Aggregate(DEFINE:([Expr1008]=Count(*)))
        |--Nested Loops(Left Semi Join, WHERE:(.[dbo].[user].[user_id] as [u].[user_id]=.[dbo].[user_personal].[user_id] as [up].[user_id]))
             |--Clustered Index Scan(OBJECT:(.[dbo].[user].[PK__user__B9BE370F7F60ED59] AS [u]), WHERE:(.[dbo].[user].[site_instance_id] as [u].[site_instance_id]=(1) AND .[dbo].[user].[graduation_class_id] as [u].[graduation_class_id]=(27) AND (.[dbo].[user].[graduation_term_id] as [u].[graduation_term_id]=(75) OR .[dbo].[user].[graduation_term_id] as [u].[graduation_term_id]=(76))))
             |--Clustered Index Scan(OBJECT:(.[dbo].[user_personal].[PK__user_per__C701FAD641EDCAC5] AS [up]))

… and with only TWO AND clauses…

|--Compute Scalar(DEFINE:([Expr1005]=CONVERT_IMPLICIT(int,[Expr1008],0)))
       |--Stream Aggregate(DEFINE:([Expr1008]=Count(*)))
            |--Hash Match(Left Semi Join, HASH:([u].[user_id])=([up].[user_id]), RESIDUAL:(.[dbo].[user].[user_id] as [u].[user_id]=.[dbo].[user_personal].[user_id] as [up].[user_id]))
                 |--Clustered Index Scan(OBJECT:(.[dbo].[user].[PK__user__B9BE370F7F60ED59] AS [u]), WHERE:(.[dbo].[user].[graduation_class_id] as [u].[graduation_class_id]=(27) AND (.[dbo].[user].[graduation_term_id] as [u].[graduation_term_id]=(75) OR .[dbo].[user].[graduation_term_id] as [u].[graduation_term_id]=(76))))
                 |--Clustered Index Scan(OBJECT:(.[dbo].[user_personal].[PK__user_per__C701FAD641EDCAC5] AS [up]))
  • 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-17T20:27:14+00:00Added an answer on June 17, 2026 at 8:27 pm

    I’m still not sure I understand your question — @Hogan had a much simpler version of your query. Nonetheless, you should have Indexes on each of the fields you join on and any field you consistently search upon.

    In your case, I’d make sure you have the following indexes:

    • user.user_id (presumably already has PK)
    • user_personal.user_id
    • user.site_instance_id, user.graduation_class_id and user.graduation_term_id

    You may also consider adding indexes to each of the 3 fields in your WHERE criteria individually, but this should prove to yield a better performance. Plus, use @Hogan’s query instead.

    Good luck.

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

Sidebar

Related Questions

I have a seemingly simple question that I need help with. I have a
A seemingly simple issue, I have an off-screen bitmap that I perform some transformations
I am stumped by a seemingly simple problem. I have two objects that I
I have a seemingly simple problem whereby I wish to reconcile two lists so
I have a seemingly simple problem, but I can't quite figure out a solution.
I have some views that I want to use EF 4.1 to query. These
I have a seemingly simple requirement, but i can't figure out how to write
I have a seemingly simple problem, but an easy solution is alluding me. I
I'm getting some weird output when running (seemingly simple) code. Here's what I have:
It seems like this seemingly simple task has never been done before. I have

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.