优化这个查询?
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,我想优化这个查询
- 计划 选择语句 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
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
P_ID
、FLAG
、C_NUMBER
、M_NUMBER
和S_NUMBER
是ABC
中的列以及P_P_ID
、P_C_NUMBER
、P_M_NUMBER
和P_S_NUMBER
是绑定变量,但这只是一个猜测。P_ID
值?哪个分数的FLAG
为“Y”?P_ID
,FLAG
,C_NUMBER
,M_NUMBER
, andS_NUMBER
are columns inABC
and thatP_P_ID
,P_C_NUMBER
,P_M_NUMBER
, andP_S_NUMBER
are bind variables but that's just a guess.P_ID
value? What fraction have aFLAG
of 'Y'?