【发布时间】:2017-02-17 10:01:06
【问题描述】:
说,我有一个简短的问题。
with test_cte as(
select *
from table1
where conditions1
)
select *
from table2
inner join test_cte
on conditions2
where conditions3
我是否正确假设查询首先通过test_cte 过滤基于conditions1 的行,将数据存储在某处,然后在加入table2 时再次通过test_cte 的剩余行?那么它在哪里存储数据呢?内存?或者这相当于
select *
from table2
inner join table1
on conditions2
where conditions3 and conditions1
但大查询更容易阅读?
【问题讨论】:
-
将 cte 想象成一个临时表,一旦您使用“表”一次,它就会消失。
-
@Snowlockk - 你是从哪里想到的? CTE 可以用作临时表或内联视图(子查询),优化器将决定哪一个;并且 CTE 不会在使用一次后立即消失。
-
调用你的 cte 一次然后再调用它。
标签: sql oracle common-table-expression