February 27, 2021 at 12:00 am
Comments posted to this topic are about the item Common Table Expression Misunderstandings
February 27, 2021 at 11:50 am
not even if we do select top 100 percent?
February 27, 2021 at 1:58 pm
In the first paragraph it says "Windowing functions are limited to the SELECT and OVER clause..."ย Correction, windowing functions are permitted in both the SELECT list as well as the ORDER BY clause.ย I'm not finding where it says this in the Docs but here's an example
select *
from (values (1),(2)) v(n)
order by row_number() over (order by v.n desc);
n
2
1
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben kรถnnen
February 27, 2021 at 3:00 pm
Good point about CTE's.
February 28, 2021 at 8:17 am
With such a name, CTE were kind of made for misconceptions. Could we rename them LVR (Local View with Recursion)?
February 28, 2021 at 12:59 pm
With such a name, CTE were kind of made for misconceptions. Could we rename them LVR (Local View with Recursion)?
BWAAAA-HAAAAA! ๐ย Let's not because then someone would want to rename iTVFs as PDIVs (Parameter Driven Inline Views). ๐
--Jeff Moden
Change is inevitable... Change for the better is not.
February 28, 2021 at 1:38 pm
BWAAAA-HAAAAA! ๐ย Let's not because then someone would want to rename iTVFs as PDIVs (Parameter Driven Inline Views). ๐
(THUMBS-UP) If it helps to leave the misconception behind, I'm on it. I start a parallel rewrite of the ANSI and T-SQL documetation...
I'll be curious to know how we ended up with this name CTE. What's so "Common" about it...
February 28, 2021 at 2:34 pm
Common is likely because it can be used anywhere on the same query multiple times unlike a derived table/subquery.
February 28, 2021 at 4:39 pm
The name common table expression comes from the way that you factor it out of multiple positions in a query expression and move it to the front. By analogy, it's something like 4x (a + b) = (4xa + 4xb), only using set and relational operations instead of arithmetic. The full-blown ANSI version, it can be factored out of several expressions and computed only once. Good optimizers do this under the covers; we just exposed it to the programmer.
Please post DDL and follow ANSI/ISO standards when asking for help.
February 28, 2021 at 4:47 pm
Jeff Moden wrote:BWAAAA-HAAAAA! ๐ย Let's not because then someone would want to rename iTVFs as PDIVs (Parameter Driven Inline Views). ๐
(THUMBS-UP) If it helps to leave the misconception behind, I'm on it. I start a parallel rewrite of the ANSI and T-SQL documetation...
I'll be curious to know how we ended up with this name CTE. What's so "Common" about it...
It's better that what they call it in Oracle... which is, "Subquery Refactoring", which is probably more accurate but doesn't exactly roll off the tongue.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 28, 2021 at 4:51 pm
The name common table expression comes from the way that you factor it out of multiple positions in a query expression and move it to the front. By analogy, it's something like 4x (a + b) = (4xa + 4xb), only using set and relational operations instead of arithmetic. The full-blown ANSI version, it can be factored out of several expressions and computed only once. Good optimizers do this under the covers; we just exposed it to the programmer.
Awesome... thanks, Joe.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 28, 2021 at 5:38 pm
Any thoughts on the pluses or minuses of using a temporary table versus a CTE? Would the size of the "virtual view" be a consideration.
February 28, 2021 at 6:16 pm
Any thoughts on the pluses or minuses of using a temporary table versus a CTE? Would the size of the "virtual view" be a consideration.
Sure...
--Jeff Moden
Change is inevitable... Change for the better is not.
February 28, 2021 at 7:29 pm
The name common table expression comes from the way that you factor it out of multiple positions in a query expression and move it to the front. By analogy, it's something like 4x (a + b) = (4xa + 4xb), only using set and relational operations instead of arithmetic. The full-blown ANSI version, it can be factored out of several expressions and computed only once. Good optimizers do this under the covers; we just exposed it to the programmer.
That's really nice and quite relatable now. It also leads to a second question... which DBMS possess such good optimizer? Is SqlServer one of them?
March 1, 2021 at 3:19 pm
jcelko212 32090 wrote:The name common table expression comes from the way that you factor it out of multiple positions in a query expression and move it to the front. By analogy, it's something like 4x (a + b) = (4xa + 4xb), only using set and relational operations instead of arithmetic. The full-blown ANSI version, it can be factored out of several expressions and computed only once. Good optimizers do this under the covers; we just exposed it to the programmer.
That's really nice and quite relatable now. It also leads to a second question... which DBMS possess such good optimizer? Is SqlServer one of them?
To be honest, all optimizers are absolutely fascinating.ย To me, they're one of the earliest forms of some serious "AI".ย I'm totally amazed that any of them work as well as they do.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply