Question on best place to use a function

  • Suppose TableA has 100 million rows. Is it better, from a performance standpoint, to write the query like such

    select * from TableA where SomeFunction(col1)=@VariableA

    or

    Select * from TableA where col1 = ReverseOfSomeFunction(@VariableA)

    Or does it make no difference? For Argument's sake, let's say there is a non-clustered index on col1.

    I hope this makes sense

    Thanks

  • better:

    Select * from TableA where col1 = ReverseOfSomeFunction(@VariableA)

    Since the index is on col1, so it would be used and speed things up and would result in an index seek for a single value; maybe in andex scan.

    if you wrap the column in a function, every row will get formatted, then compared, which requires a table scan.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Totally Agreed. To take advantage of index you must use "where col1 = function(@var1)".

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply