加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – Oracle优化器会在同一个SELECT中使用多个提示吗?

发布时间:2020-12-12 16:10:47 所属栏目:MsSql教程 来源:网络整理
导读:我试图优化查询性能,而不得不诉诸于使用优化器提示.但是我从来没有学到过优化器是否会一次使用多个提示. 例如 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
我试图优化查询性能,而不得不诉诸于使用优化器提示.但是我从来没有学到过优化器是否会一次使用多个提示.

例如

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;

解释计划显示相同的成本,但我知道这只是一个估计.

请假设已经计算了所有表和索引统计信息. FYI,索引dcf_vol_prospect_ids_idx位于i.solicitor_id列上.

谢谢,

解决方法

尝试在单个注释块中指定所有提示,如本例中的精彩Oracle文档( http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/hintsref.htm)所示.

16.2.1 Specifying a Full Set of Hints

When using hints,in some cases,you
might need to specify a full set of
hints in order to ensure the optimal
execution plan. For example,if you
have a very complex query,which
consists of many table joins,and if
you specify only the INDEX hint for a
given table,then the optimizer needs
to determine the remaining access
paths to be used,as well as the
corresponding join methods. Therefore,
even though you gave the INDEX hint,
the optimizer might not necessarily
use that hint,because the optimizer
might have determined that the
requested index cannot be used due to
the join methods and access paths
selected by the optimizer.

In Example 16-1,the LEADING hint
specifies the exact join order to be
used; the join methods to be used on
the different tables are also
specified.

Example 16-1 Specifying a Full Set of
Hints

SELECT /*+ LEADING(e2 e1) USE_NL(e1) INDEX(e1 emp_emp_id_pk)
           USE_MERGE(j) FULL(j) */
    e1.first_name,e1.last_name,j.job_id,sum(e2.salary) total_sal  
FROM employees e1,employees e2,job_history j
WHERE e1.employee_id = e2.manager_id
  AND e1.employee_id = j.employee_id
  AND e1.hire_date = j.start_date
GROUP BY e1.first_name,j.job_id   ORDER BY total_sal;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读