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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:11:45+00:00 2026-06-05T23:11:45+00:00

am trying to squeeze some performance out of this query, any help would be

  • 0

am trying to squeeze some performance out of this query, any help would be appreciated, the only thing I can do is drop the order by on the second statement as it is ordered by primary key

--SET STATISTICS TIME ON

DECLARE             
        @MasterAdGroupId Int = 3469476,
        @IncludeDeleted Bit = 1,
        @Deleted Bit = 0,
        @IncludeDirty Bit= 0,
        @Dirty Bit =1,
        @IncludeDupes Bit=0,
        @OrderByText Bit= 1,
        @UseInDisplayNetworkOnly Bit=0

BEGIN

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
IF @OrderByText=1 
BEGIN
    SELECT MasterKeywordId, Text, URL, MasterAdGroupId, mk.KeywordTemplateId, Dirty, mk.Deleted, Negative, Duplicate  
      FROM admanMasterKeyword_tbl mk
INNER JOIN admanKeywordTemplate_tbl kt on kt.KeywordTemplateId = mk.KeywordTemplateId
     WHERE MasterAdGroupId = @MasterAdGroupId 
       AND mk.Deleted = CASE WHEN @IncludeDeleted=0 THEN @Deleted ELSE mk.Deleted END
       AND Dirty = CASE WHEN @IncludeDirty=0 THEN @Dirty ELSE Dirty END
       AND Duplicate = CASE WHEN @IncludeDupes=1 THEN Duplicate ELSE 0 END
       AND UseInDisplayNetwork = CASE WHEN @UseInDisplayNetworkOnly=1 THEN 1 ELSE UseInDisplayNetwork END
  ORDER BY Text 
END
ELSE
BEGIN
    SELECT MasterKeywordId, Text, URL, MasterAdGroupId, mk.KeywordTemplateId, Dirty, mk.Deleted, Negative, Duplicate  
      FROM admanMasterKeyword_tbl mk
INNER JOIN admanKeywordTemplate_tbl kt on kt.KeywordTemplateId = mk.KeywordTemplateId
     WHERE MasterAdGroupId = @MasterAdGroupId 
       AND mk.Deleted = CASE WHEN @IncludeDeleted=0 THEN @Deleted ELSE mk.Deleted END
       AND Dirty = CASE WHEN @IncludeDirty=0 THEN @Dirty ELSE Dirty END
       AND Duplicate = CASE WHEN @IncludeDupes=1 THEN Duplicate ELSE 0 END
       AND UseInDisplayNetwork = CASE WHEN @UseInDisplayNetworkOnly=1 THEN 1 ELSE UseInDisplayNetwork END
  ORDER BY MasterKeywordId 
END

END
  • 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-05T23:11:47+00:00Added an answer on June 5, 2026 at 11:11 pm

    This isn’t going to change anything performance wise, but if all you’re changing in the two queries is how they are ordered (I couldn’t see any differences), you could put a CASE statement right in the ORDER BY and not have to repeat yourself or do an IF statement at all:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
    
        SELECT MasterKeywordId, Text, URL, MasterAdGroupId, mk.KeywordTemplateId, Dirty, mk.Deleted, Negative, Duplicate  
          FROM admanMasterKeyword_tbl mk
    INNER JOIN admanKeywordTemplate_tbl kt on kt.KeywordTemplateId = mk.KeywordTemplateId
         WHERE MasterAdGroupId = @MasterAdGroupId 
           AND mk.Deleted = CASE WHEN @IncludeDeleted=0 THEN @Deleted ELSE mk.Deleted END
           AND Dirty = CASE WHEN @IncludeDirty=0 THEN @Dirty ELSE Dirty END
           AND Duplicate = CASE WHEN @IncludeDupes=1 THEN Duplicate ELSE 0 END
           AND UseInDisplayNetwork = CASE WHEN @UseInDisplayNetworkOnly=1 THEN 1 ELSE UseInDisplayNetwork END
      ORDER BY (CASE WHEN @OrderByText = 1 THEN Text ELSE MasterKeywordId END) 
    

    What does the query plan look like for this query? Anywhere you could create indices?

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

Sidebar

Related Questions

I'm trying to squeeze some performance increases out of my iPhone OpenGL ES application.
If I'm am trying to squeeze every last drop of performance out of a
I am trying to squeeze the most performance out of a Linux block driver
Background, I'm running a Zend Framework application. Trying to squeeze the most performance out
I am trying to squeeze out any little bit of perf possible, and as
Trying to parse an HTML document and extract some elements (any links to text
I'm trying to squeeze every bit of performance in my Delphi application and now
My brain is fried trying to squeeze some work in before the holiday. I'm
I'm trying to simply move the actionBar down 75 pixels so I can squeeze
I'm trying to squeeze as much out of my memory as possible. 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.