sql - Converting ROW_NUMBER column affects performance -


i need know reason behind why there big performance difference when converting column generated row_number window function data type.

example :

with mycte  (     select row_number() on (order id asc) rownumber, * (         select distinct * (             select                  j.*,                  -- other columns here             table j                  -- join other tables here )   -- filter records select  *    mycte convert(int, rownumber) between convert(int, 40000) ,  convert(int, 40010) 

if convert rownumbercolumn first int execute 3 secs ideal.

where convert(int, rownumber) between convert(int, 40000) ,  convert(int, 40010)` 

but if not convert it, took 1 minute execute query.

where rownumber between convert(int, 40000) ,  convert(int, 40010) 

can me concept behind this?

row_number() function returns value of bigint datatype , constant 40000 returns int.

because of difference in datatypes (yes, int , bigint) sql-server can't estimate carnality , choose not optimal execution plan.

you should see on actual execution plan.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -