I have function with CTE which looks like this:
function param(p_userId, p_templateId) with a(select...), b (select..), c (insert..returning..), d (update..returning..), ...k(select..) insert ... select * from k where userId = p_userId and templateId = p_templateId
I'm able to put the where clause right at the begining in the a
CTE. If I place the condition at the end like I have it now, will it filtered the rows out at the earliest or at the latest time? What is faster?
Basically what I do is, in the CTE's which appear sooner, like the a
or b
, (rather then k
), I'm prefetching data or precalculating columns in order to use them later in the following CTEs.
Hope this question is still not too vague.