When I use CTE’s, the database creates a cache type?
No, these concepts are unrelated. The cache is created as required by a number of circumstances. Of course, CTE can take advantage of what’s in the cache, you can cache things and take advantage of them later, but that’s circumstantial and it occurs as a side effect, not because CTE depends on it.
You may have gotten a different result for several reasons, it may be because the query can be better processed, better planned with more details. But of course the cache may be influencing as well. They are too variable to state without knowing the concrete case in detail.
If you don’t know how to take the test you may be gathering false information.
What would be relevant, in the choice of use, between JOIN’s and SUBQUERIES’s or CTE’s?
The question doesn’t make much sense. It has to use what is most pertinent with what it needs and what gives best result in the specific case, and it is not restricted to these 3 forms, which are even antagonistic. In general it is possible to do anything without these 3 things, but it can be easier or more optimized to choose one of them in a certain scenario.
The question speaks in an example scenario, but it has no example, it has a result that is not even known how it was obtained.
Which sgbd was used?
– Jefferson Quesado
@Jeffersonquesado Which I used in question, is Sqlserver 2008 R2, from an ERP system. There are several tables, several joins, cases, calculations, etc. What I did was practically separate steps by CTE.
– rbz
He has a tool that allows to see the execution plan, but exactly now I can not send print because I’m on the mobile. There is also a change in the execution of the query that shows what was actually executed, making it possible to find bottlenecks and even suggesting indexes to improve the query
– Jefferson Quesado
Whoa, cool it there... Then put it on for us!
– rbz