Click here to Skip to main content
14,865,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to create sp for grid paging and I am using CTE,

my CTE query is ,

SQL
with cte as
(select .......)
select * from cte


this query takes 250ms to execute,

but when I am adding the count() for counting the cte query record it is taking about 700ms to execute....

after adding count() cte like,

SQL
with cte as
(select .......)
,cte2 as (select count(column) as cnt from cte)
select cnt,* from cte,cte2


as I am runing single select query with count() it is taking about 80ms

I need the row count of cte query with better performance,

please let me know if it is any thing wrong.

Thanks.
Posted

1 solution

Again[^].
Why are you wondering? You define two CTE-s on to of the same records sets, and one is recursive. Try to run a profiler to see what locks are occurring. If you know better query plan than the optimizer, add a hint[^] to it.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900