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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:00:25+00:00 2026-05-26T18:00:25+00:00

From working on this specific situation, it was news to me that the logic

  • 0

From working on this specific situation, it was news to me that the logic operators are not short circuited in SQL.

I routinely do something along these lines in the where clause (usually when dealing with search queries):

WHERE
   (@Description IS NULL OR @Description = myTable.Description)

Which, even if it’s not short-circuited in this example, doesn’t really matter. However, when dealing with the fulltext search functions, it does matter.. If the second part of that query was CONTAINS(myTable.Description, @Description), it wouldn’t work because the variable is not allowed to be null or empty for these functions.

I found out the WHEN statements of CASE are executed in order, so I can change my query like so to ensure the fulltext lookup is only called when needed, along with changing the variable from null to '""' when it is null to allow the query to execute:

WHERE
   (CASE WHEN @Description = '""' THEN 1 WHEN CONTAINS(myTable.Description, @Description) THEN 1 ELSE 0 END = 1)

The above code should prevent the full-text query piece from executing unless there is actually a value to search with.

My question is, if I run this query where @Description is '""', there is still quite a bit of time in the execution plan spent dealing with clustered index seeks and fulltextmatch, even though that table and search does not end up being used at all: is there any way to avoid this?

I’m trying to get this out of a hardcoded dynamic query and into a stored procedure, but if the procedure ends up being slower, I’m not sure I can justify it.

  • 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-26T18:00:26+00:00Added an answer on May 26, 2026 at 6:00 pm

    In case anyone else runs into a scenario like this, this is what I ended up doing, which is pretty close to what M_M was getting at; I broke away the full-text pieces and placed them behind branches:

    DECLARE @TableBfullSearch TABLE (TableAId int)
    IF(@TableBSearchInfo IS NOT NULL)
       INSERT INTO @TableBfullSearch
       SELECT
          TableAId
       FROM
          TableB
       WHERE
       ...(fulltext search)...
    
    DECLARE @TableCfullSearch TABLE (TableAId int)
    IF(@TableCSearchInfo IS NOT NULL)
       INSERT INTO @TableCfullSearch
       SELECT
          TableAId
       FROM
          TableC
       WHERE
       ...(fulltext search)...
    
    --main query with this addition in the where clause
    SELECT
      ...
    FROM
       TableA
    WHERE
       ...
       AND (@TableBSearchInfo IS NULL OR TableAId IN (SELECT TableAId FROM @TableBfullSearch))
       AND (@TableCSearchInfo IS NULL OR TableAId IN (SELECT TableAId FROM @TableCfullSearch))
    

    I think that’s probably about as good as it’ll get without some sort of dynamic query

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

Sidebar

Related Questions

I have this working query that outputs URL and click counts from database. <?php
I have this tabs that are working perfect in any browser apart from IE
This is a little snippet from a little flash game I'm working on: This
I have this working query: $q = $this->db->query('SELECT u.name FROM users u JOIN user_group
i got this code working and it to return the last tweet from my
I could swear this was working the other day: var resultSet = (from o
I have a working script from someone, there in is this line: this.event =
From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended
Why this query doesn’t working: SELECT name FROM ( SELECT name FROM table1 UNION
This is heavily trimmed down source code from a webpage I'm working on right

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.