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
Post a Comment