优化这个查询?

发布于 2024-11-28 18:43:02 字数 638 浏览 0 评论 0原文

SELECT MAX (tran_date)
FROM   abc
WHERE  p_id = p_p_id
AND    flag = 'Y'
AND    (   (    p_c_number IS NULL
            AND c_number IS NULL
           )
        OR (c_number = p_c_number)
       )
AND    (   (    p_m_number IS NULL
            AND m_number IS NULL
           )
        OR (m_number = p_m_number)
       )
AND    (   (    p_s_number IS NULL
            AND s_number IS NULL
           )
        OR (s_number = p_s_number)
       );

我使用 oracle 作为 RDBMS,我想优化这个查询

  1. 计划 选择语句 ALL_ROWS 成本:357 字节:39 基数:1
    2 SORT AGGREGATE 字节:39 基数:1
    1 个表访问全表 abc 成本:357 字节:312 基数:8
SELECT MAX (tran_date)
FROM   abc
WHERE  p_id = p_p_id
AND    flag = 'Y'
AND    (   (    p_c_number IS NULL
            AND c_number IS NULL
           )
        OR (c_number = p_c_number)
       )
AND    (   (    p_m_number IS NULL
            AND m_number IS NULL
           )
        OR (m_number = p_m_number)
       )
AND    (   (    p_s_number IS NULL
            AND s_number IS NULL
           )
        OR (s_number = p_s_number)
       );

I am using oracle as RDBMS ,i want to optimize this query

  1. Plan
    SELECT STATEMENT ALL_ROWSCost: 357 Bytes: 39 Cardinality: 1
    2 SORT AGGREGATE Bytes: 39 Cardinality: 1
    1 TABLE ACCESS FULL TABLE abc Cost: 357 Bytes: 312 Cardinality: 8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

折戟 2024-12-05 18:43:02
  • 能把查询计划贴出来吗?
  • 表上存在哪些索引?
  • 哪些引用是列名,哪些是绑定变量?我的猜测是 P_IDFLAGC_NUMBERM_NUMBERS_NUMBERABC 中的列以及 P_P_IDP_C_NUMBERP_M_NUMBERP_S_NUMBER 是绑定变量,但这只是一个猜测。
  • 各种条件的选择性如何?特别是,表中的哪些行具有特定的 P_ID 值?哪个分数的 FLAG 为“Y”?
  • Can you post the query plan?
  • What indexes exist on the table?
  • Which of the references are column names and which are bind variables? My guess is that P_ID, FLAG, C_NUMBER, M_NUMBER, and S_NUMBER are columns in ABC and that P_P_ID, P_C_NUMBER, P_M_NUMBER, and P_S_NUMBER are bind variables but that's just a guess.
  • How selective are the various conditions? In particular, what fraction of the rows in the table have a particular P_ID value? What fraction have a FLAG of 'Y'?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文