使用子查询优化存储过程
我正在研究使用子查询的存储过程的优化。 我需要替换这个子查询以获得更少的执行时间。
代码:
SELECT t1.*,
detail= case when ( DC_ID in ( select DC_ID
from TableFinale1
where frais is not null
and WDT is not null
and type <> 'CDFS'
)
)
then 'OK'
Else ''
End
into TableFinale2
From TableFinale1 t1
I'im working on optimization of stored procedure that uses a subquery.
I need to replace this subquery to get less execution time.
code:
SELECT t1.*,
detail= case when ( DC_ID in ( select DC_ID
from TableFinale1
where frais is not null
and WDT is not null
and type <> 'CDFS'
)
)
then 'OK'
Else ''
End
into TableFinale2
From TableFinale1 t1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以切换到 JOIN,但是...如果有超过 1 个
DC_ID
具有非空fraisT1
记录code>、非空WDT
和type<>'CDFS
。因此,除非您的数据符合模型,否则它并不完全是 1:1。You could switch to a JOIN, BUT... this will cause duplicate
T1
records if there are more than 1DC_ID
that have a non-nullfrais
, a non-nullWDT
, and atype<>'CDFS
. So it's not exactly 1:1 unless your data fits the mold.如果没有查询计划,很难预测性能变化。如果TableFinale1.DC_ID上没有索引,
也许准备好的过滤和索引临时表会有所帮助。假设 DC_ID
bigint
:It is hard to predict performance changes without a query plan. If there are no indexes on TableFinale1.DC_ID,
maybe a prepared filtered and indexed temporary table will help. Assuming DC_ID
bigint
: