码迷,mamicode.com
首页 > 其他好文 > 详细

HINT 不生效?

时间:2015-09-23 17:05:38      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

今天有个徒弟找我看一条SQL

SELECT /*+  use_hash(REGION,MPI) */
    REGION.REGION_CODE,
    REGION.REGION_NAME,
    MPI.YEARS,
    SUM(MPI.MPI_COUNT) SUM_MPI_COUNT
  FROM
    (SELECT /*+ index_ffs(T_REGION T_REGION_INDEX) */ REGION_CODE, REGION_NAME FROM T_REGION 
      where REGION_CODE  is not null
      and REGION_NAME is not null
    ) REGION
  LEFT JOIN
    ( SELECT /*+ index_ffs(MPI_PERSON_INDEX MPI_PERSON_INDEX_INDEX) */ AR_CD,
      TO_CHAR(CREATETIME,‘YYYY‘) YEARS,
      COUNT(1) AS MPI_COUNT
    FROM MPI_PERSON_INDEX
    GROUP BY AR_CD,
      TO_CHAR(CREATETIME,‘YYYY‘)
    ) MPI
  ON REGION.REGION_CODE=MPI.AR_CD
  GROUP BY REGION.REGION_CODE,
    REGION.REGION_NAME,
    MPI.YEARS

加了hint use_hash不生效, 然后让他生成10053 trace,结果trace里面没有 use_hash 的hint ...,但是有 index_ffs 的hint 太奇怪了,于是把sql改了

SELECT /*+ use_hash(region,mpi) */
 REGION.REGION_CODE,
 REGION.REGION_NAME,
 MPI.YEARS,
 SUM(MPI.MPI_COUNT) SUM_MPI_COUNT
  FROM (SELECT /*+ index_ffs(T_REGION T_REGION_INDEX) */
         REGION_CODE, REGION_NAME
          FROM T_REGION
         where REGION_CODE is not null
           and REGION_NAME is not null) REGION,
       (SELECT /*+ index_ffs(MPI_PERSON_INDEX MPI_PERSON_INDEX_INDEX) */
         AR_CD, TO_CHAR(CREATETIME, ‘YYYY‘) YEARS, COUNT(1) AS MPI_COUNT
          FROM MPI_PERSON_INDEX
         GROUP BY AR_CD, TO_CHAR(CREATETIME, ‘YYYY‘)) MPI
 where REGION.REGION_CODE = MPI.AR_CD(+)
 GROUP BY REGION.REGION_CODE, REGION.REGION_NAME, MPI.YEARS


改成 + 方式居然hint生效了, 因为无法连接他电脑,就没有深入研究下去了,先记录一下。



版权声明:本文为博主原创文章,未经博主允许不得转载。

HINT 不生效?

标签:

原文地址:http://blog.csdn.net/robinson1988/article/details/48682059

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!