Oracle 优化器会在同一个 SELECT 中使用多个提示吗?
我正在尝试优化查询性能,并且不得不求助于使用优化器提示。 但我从来不知道优化器是否会一次使用多个提示。
例如,
SELECT /*+ INDEX(i dcf_vol_prospect_ids_idx)*/
/*+ LEADING(i vol) */
/*+ ALL_ROWS */
i.id_number,
...
FROM i_table i
JOIN vol_table vol on vol.id_number = i.id_number
JOIN to_a_bunch_of_other_tables...
WHERE i.solicitor_id = '123'
AND vol.solicitable_ind = 1;
解释计划显示了相同的成本,但我知道这只是一个估计。
请假设所有表和索引统计信息均已计算。 仅供参考,索引 dcf_vol_prospect_ids_idx 位于 i.solicitor_id 列上。
谢谢,
炖
I'm trying to optimize query performance and have had to resort to using optimizer hints. But I've never learned if the optimizer will use more than one hint at a time.
e.g.
SELECT /*+ INDEX(i dcf_vol_prospect_ids_idx)*/
/*+ LEADING(i vol) */
/*+ ALL_ROWS */
i.id_number,
...
FROM i_table i
JOIN vol_table vol on vol.id_number = i.id_number
JOIN to_a_bunch_of_other_tables...
WHERE i.solicitor_id = '123'
AND vol.solicitable_ind = 1;
The explain plan shows the same cost, but I know that's just an estimate.
Please assume that all table and index statistics have been calculated. FYI, the index dcf_vol_prospect_ids_idx is on the i.solicitor_id column.
Thanks,
Stew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在单个注释块中指定所有提示,如精彩的 Oracle 文档 (http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/hintsref.htm)。
Try specifying all the hints in a single comment block, as shown in this example from the wonderful Oracle documentation (http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/hintsref.htm).
Oracle 19c 引入了提示使用情况报告功能:
它显示了另一部分
提示报告
:Oracle 19c introduced Hint Usage Reporting feature:
It shows another section
Hint Report
:事实上,《Cost-Based Oracle Fundamentals》一书的作者 Jonathan Lewis 的建议是,如果 CBO 未能找到正确的计划,您需要接管 CBO 的工作并“分层”提示 - 平均查询中每个表有两个提示。
原因是,一个暗示可能会导致另一个糟糕的计划,甚至可能比国会预算办公室在没有帮助的情况下更糟糕。 如果国会预算办公室错了,你需要向其提供整个计划,而不仅仅是推动正确的方向。
In fact, the recommendation of Jonathan Lewis, Author of Cost-Based Oracle Fundamentals is that if the CBO fails at finding the correct plan, you need to take over the job of the CBO and "layer-in" the hints - an average of two hints per table in the query.
The reason is that one hint could lead to yet another bad and possibly even worse plan than the CBO would get unaided. If the CBO is wrong, you need to give it the whole plan, not just a nudge in the right direction.