如何调试此 sql 查询以避免超时?

How can I debug this sql query to avoid timeout?

我有一个 SQL 查询,尽管它让我头疼,但实际上并没有做很多事情。老实说,我不知道如何调试这个查询,因为每当我 运行 它时,它会持续 运行 几分钟,直到我最终强行退出 SQL 开发人员。即使取消查询也需要很长时间。

任何建议、帮助,非常感谢!!

SELECT
    view2.some_id,
    SUM(view1.qty)
FROM
    someview view1,
    someview view2
WHERE
        view1.lot = view2.some_id
    AND view2.some_prefix = 'ABCD'
    AND view2.some_prefix = 'EFGH'
GROUP BY
    view2.some_id

我不知道为什么会导致超时。这个简短的陈述 (s2) 是另一个陈述的一部分:

CREATE OR REPLACE FORCE EDITIONABLE VIEW "VIEW" AS 
WITH s1 AS
        (SELECT something
           FROM sometable st
          WHERE st.side = 'TO'
          group by st.lot),
    s2 AS
        (SELECT
      view2.some_id,
      SUM(view1.qty)
  FROM
      someview view1,
      someview view2
  WHERE
          view1.lot = view2.some_id
      AND view2.some_prefix = 'ABCD'
      AND view2.some_prefix = 'EFGH'
  GROUP BY
      view2.some_id)
 SELECT 
        t2.some,
        t2.some,
        t2.some,
        s1.some,
        t2.some,
        t2.some,
        s2.some,
        s2.some / s1.some * t2.some
   FROM
        sometable t2, s1, s2
        WHERE t2.some = s1.some
        AND t2.some = s2.some
        AND t2.some = 'FROM' AND t2.some = 'VN1' AND t2.some_prefix = 'ABCD'; 

请给我任何提示。

更新:我检查了每个 table:

的行数
sometable st (s1): 2.805.809
view2 (s2): 21.877
view1 (s2): 6.144.386
t2: 121.043

好像没那么多....

我将从删除 s2 中的隐式连接(不应使用)开始

语法已过时,遗留代码。 我想我找到了原因。原始(遗留代码)查询语句是 - 还是使用? - CTE(常见 table 表达式)不适用于索引。那是我在某处读到的。我不知道这是否真的是原因,但是,这是我的版本,它有效:

SELECT
  some,
  some,
  some,
  some,
  some,
  some,
  some,
  some / some * some
FROM
  (
    SELECT
      *
    FROM
      (
        SELECT
          a.somelot,
          b.someqty vq
        FROM
          (
            (
              SELECT
                view2.some_id somelot,
                view2.someother_id --added this
              FROM
                someview view2
              WHERE
                view2.some_prefix = 'ABCD'
                AND view2.some_prefix = 'EFGH'
            ) a
            JOIN (
              SELECT
                view1.lot,
                SUM(view1.qty) qty
              FROM
                someview view1
              GROUP BY
                lot,
                qty
            ) b ON a.someother_id = b.lot
          )
      ) s2
      JOIN (
        SELECT
          lot,
          SUM(trans_qty) pq
        FROM
          someview
        WHERE
          side = 'TO'
        GROUP BY
          lot,
          trans_qty
      ) s1 ON s1.lot = s2.lot
      JOIN (
        SELECT
          lot,
          some,
          some,
          trans_qty trans_qty,
          some
        FROM
          someview
        WHERE
          some = 'ZZZZ'
          AND some = 'XXX'
          AND some_prefix = 'WXYZ'
      ) t2 ON t2.lot = s1.lot
      AND t2.lot = s2.lot
  )