全称 common table expressions,表示临时结果,用
with as
语句,可以在其他SQL中引用,如select、insert、update和delete。
相当于用with as
语句创建临时表,SQL结构清晰,并且结果可以复用。
下面是使用样例
with c1 as (
select * from t1
)
,with c2 as (
select * from c1
)
select * from c2 where id = 100;
as materialized or not as materialized 在PG12之前,with语句都是通过将子查询先进行
物化
,这就导致了一个问题:with子查询外的条件无法内推到里面,并且会产生物化视图,会影响查询性能
。 使用PG12会自动判断是否物化(自测得出,版本12.2),但是有些场景需要我们手动控制才能保证查询效率。
只有其中一个with as
物化了
没有物化的
全部物化
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有