Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Way of Passing the parameter into the function and performance gettin impacted

$
0
0
 

Hi all,

while doing something i have come across something strange.

i have a inline table value function which takes the 1  parameter which  get used in the join condition and i have ran the query with 2 approaches and got the result as shown below

Approach 1

select * from Fn_inline_table_udf (41249)

in the above scenario query keeps running and as per query estimated plan it’s not using the index hence it has taken the time .

Approach 2

declare @PREV_SNAPSHOT_DATE_SK_ID AS INT  = 41249

select * from Fn_inline_table_udf (@PREV_SNAPSHOT_DATE_SK_ID )

in the above scenario getting the output in 2 sec and as per the plan it make use of index.

I am not able to understand what is the difference between above two approach, due to that in one approach sql is making use of index and not in second. I have also given a thought on implicit conversion hence ran the query with below way as well as

select * from Fn_inline_table_udf (cast(41249 as bigint))

But still function is not returning the result as not using the index again.

does anyone has idea, why sql engine is behaving like that?


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>