简体   繁体   English

SQL优化:CONNECT BY…开始于

[英]SQL Optimization: CONNECT BY … START WITH

I have a query using CONNECT BY and START WITH statement like below. 我有一个使用CONNECT BYSTART WITH语句的查询,如下所示。 The query in the IN clause took less than 5 seconds to run and returns 3000 rows. IN子句中的查询运行少于5秒,并返回3000行。 fact_table contains 20M of records. fact_table包含20M条记录。 How can I optimize this SQL below because this query takes forever to run :( 我如何在下面优化此SQL,因为此查询需要永远运行:(

SELECT DISTINCT CONNECT_BY_ROOT a.dst_ID_key AS root_ID_key, a.src_ID_key
  FROM fact_table a
  CONNECT BY NOCYCLE PRIOR a.src_ID_key = a.dst_ID_key
   START WITH a.dst_ID_key IN (SELECT b.ID_key
                           FROM TableA b
                           JOIN TableB c
                             ON (c.name = b.name AND c.school = b.school)
                          WHERE b.status = 'Active')

Using "in" is very slow. 使用“ in”非常慢。
If this data doesn't need real-time update. 如果此数据不需要实时更新。
I think you can try this: 我认为您可以尝试以下方法:
1、Don't use distinct 1,别用
2、Use table connection instead of 'in' 2,使用表连接代替“ in”
3、Use materialized view 3,使用物化视图
Hope helps.Wait for a better answer too. 希望有帮助,也等待更好的答案。 : ) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM