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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:42:23+00:00 2026-05-20T11:42:23+00:00

I have a query: SELECT someFields FROM someTable WHERE cheapLookup=1 AND (CAST(someField as FLOAT)/otherField)<0.9

  • 0

I have a query:

SELECT 
    someFields 
FROM 
    someTable 
WHERE 
    cheapLookup=1 
    AND (CAST(someField as FLOAT)/otherField)<0.9

So, will the CAST and division be performed in the case that cheapLookup is 0? If not, how can I avoid the calculation in this case?

  • 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-20T11:42:24+00:00Added an answer on May 20, 2026 at 11:42 am

    It depends on the query plan, which is determined by the estimated cost of each considered alternative plan that would produce correct results.

    If the predicate ‘cheapLookup = 1’ can use an index, and it is sufficiently selective, SQL Server would likely choose to seek on that index and apply the second predicate as a residual (that is, only evaluating it on rows that are matched by the seeking operation).

    On the other hand, if cheapLookup is not the leading key in an index, or if it is not very selective, SQL Server might choose to scan, applying both predicates to every row encountered.

    The second predicate will not be chosen for a seeking operation, unless there happens to be an indexed computed column on the whole expression, and using that index turns out to be the cheapest way to execute the whole query. If a suitable index exists, SQL Server would seek on ‘second predicate result < 0.9’, and apply ‘cheapLookup=1’ as a residual. There is also the possibility that the indexed computed column has cheapLookup as its second key, which would result in a pure seek, with no residual.

    The other thing about the second predicate is that without a computed column (whether or not indexed), SQL Server will have to guess at the selectivity of the expression. With the computed column, the server might be able to create statistics on the expression-result column, which will help the optimizer. Note that a computed column on ‘CAST(someField as FLOAT)/otherField’ would have to be persisted before it could be indexed or have statistics created on it, because it contains an imprecise data type.

    In summary, it’s not the complexity of the expression that counts so much as the estimated cost of the whole plan that uses each of the available access methods considered by the optimizer.

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

Sidebar

Related Questions

I have a query: select substr(name,7,50) as location, points,sum(if (p1=r1,10,-10))as total from dq.data group
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: select qa_returns_items.item_code, (CASE status_code WHEN 11 THEN (qa_returns_items.item_quantity - qa_returns_residues.item_quantity)
I have a query: SELECT ID FROM requests WHERE date <operator> <expression> I need
I have a query that selects some fields to display from a table SELECT
I have query Select * from table1 where name like '%Whateveruserpassintextbox%' . When user
I have table tree. I have query: SELECT * FROM tree WHERE pid =10
I have a query that looks like the following: SELECT someString FROM ( SELECT
I have the following sql query: SELECT field_number, COUNT(*) AS c FROM lead_detail WHERE
I have this query: var list = (from t1 in context1.SomeTable join t2 in

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.