If it is recursive it is still considered a loop.
Although one statement is set based, calling it over and over can be considered a loop. This is an argument about the definition or wording based on the context being used. They are set based statements but the processing is considered in simple terms a looping process.
For those interested here is a nice little write up about performance with CTE's:
但如果你用足够强大的放大镜观察的话,所有的集合操作都是循环的。最终,代码在 CPU 上运行,CPU 执行在离散内存区域上运行的串行指令流。换句话说,不存在面向集合的硬件。 “面向集合”是一个逻辑概念。 所有 SQL 操作最终都是使用某种形式的循环来实现的,这一事实是一个实现细节。
They are set based. Recursive sets are still sets.
But all set operations are, if you look with a powerful enough magnifier glass, loops. Ultimately the code runs on CPUs and CPUs execute a stream of serial instructions that operate on discrete regions of memory. In other words, there is no set oriented hardware. Being 'set oriented' is a logical concept. The fact that all SQL operations are ultimately implemented using some form of a loop is an implementation detail.
I think the distinction that needs to be done is "tail recursion" versus "general recursion".
All tail recursions can be implemented as loops - without the need for a Stack.
General recursion support can also be implemented as a Loop - but with a stack.
Recursive CTEs are Tail recursions and hence essentially a Loop. The only difference is the terminating condition is handled by SQL semantics/execution engine. The output from each Loop iteration is UNIONed or whatever set op you specify.
发布评论
评论(3)
如果它是递归的,它仍然被视为循环。
尽管一个语句是基于集合的,但一遍又一遍地调用它可以被视为循环。这是基于所使用的上下文的关于定义或措辞的争论。它们是基于集合的语句,但简单来说,处理被视为循环过程。
对于那些感兴趣的人来说,这里有一篇关于 CTE 性能的精彩小文章:
http://explainextended.com/2009/11/18/sql-server-are-the-recursive-ctes-really-set-based/
If it is recursive it is still considered a loop.
Although one statement is set based, calling it over and over can be considered a loop. This is an argument about the definition or wording based on the context being used. They are set based statements but the processing is considered in simple terms a looping process.
For those interested here is a nice little write up about performance with CTE's:
http://explainextended.com/2009/11/18/sql-server-are-the-recursive-ctes-really-set-based/
它们是基于设置的。递归集仍然是集。
但如果你用足够强大的放大镜观察的话,所有的集合操作都是循环的。最终,代码在 CPU 上运行,CPU 执行在离散内存区域上运行的串行指令流。换句话说,不存在面向集合的硬件。 “面向集合”是一个逻辑概念。 所有 SQL 操作最终都是使用某种形式的循环来实现的,这一事实是一个实现细节。
They are set based. Recursive sets are still sets.
But all set operations are, if you look with a powerful enough magnifier glass, loops. Ultimately the code runs on CPUs and CPUs execute a stream of serial instructions that operate on discrete regions of memory. In other words, there is no set oriented hardware. Being 'set oriented' is a logical concept. The fact that all SQL operations are ultimately implemented using some form of a loop is an implementation detail.
我认为需要区分的是“尾递归”与“一般递归”。
所有尾递归都可以作为循环实现 - 不需要堆栈。
一般递归支持也可以实现为循环 - 但使用堆栈。
递归 CTE 是尾递归,因此本质上是一个循环。唯一的区别是终止条件由 SQL 语义/执行引擎处理。每个循环迭代的输出都是 UNIONed 或您指定的任何集合操作。
I think the distinction that needs to be done is "tail recursion" versus "general recursion".
All tail recursions can be implemented as loops - without the need for a Stack.
General recursion support can also be implemented as a Loop - but with a stack.
Recursive CTEs are Tail recursions and hence essentially a Loop. The only difference is the terminating condition is handled by SQL semantics/execution engine. The output from each Loop iteration is UNIONed or whatever set op you specify.