如何让oracle的select强制走索引
发布网友
发布时间:2022-04-30 11:35
我来回答
共2个回答
懂视网
时间:2022-04-30 15:56
例如:
select /*+INDEX(xe emp_postproperty)*/ * from xemployee xe where xe.POSTPROPERTY=‘1‘
格式:
1、/*+INDEX(xe emp_postproperty)*/ 这里的/*...*/中间不要有空格
2、表名要用别名,即:以上面的sql语句为例,要使用xe ,而不是xemployee
3、数据类型不同也会影响索引,例如 where xe.POSTPROPERTY=‘1‘ where xe.POSTPROPERTY=1
如何让oracle的select强制走索
标签:
热心网友
时间:2022-04-30 13:04
CREATE OR REPLACE VIEW V_RES_CBA AS
SELECT /*+INDEX(SEG IDX_T_RES_ALLOSEG_ALLOID)*/
ALLO.ALLOID AS RESID,
NULL AS AWB,
ALLO.ALLOTMENT AS ALLO_ID,
DAYS.FDATE + NVL(SEG.DAYSDISP, 0) AS FDATE,
ALLO.SPECULD AS SPECULD
FROM T_RES_ALLO ALLO, T_RES_ALLOSEG SEG, V_FDATE DAYS
WHERE ALLO.ALLOID = SEG.ALLOID
AND ((ALLO.ALLOIND = 'A' AND ALLO.ALLO_DATE = DAYS.FDATE) OR
(ALLO.ALLOIND = 'S' AND
NVL(ALLO.SDATE, ALLO.ALLO_DATE) = DAYS.FDATE))
UNION
SELECT /*+INDEX(SEG IDX_T_RES_ALLOSEG_ALLOID)*/
ALLO.ALLOID AS RESID,
NULL AS AWB,
ALLO.ALLOTMENT AS ALLO_ID,
DAYS.FDATE + NVL(SEG.DAYSDISP, 0) AS FDATE,
ALLO.SPECULD AS SPECULD
FROM T_RES_ALLO ALLO, T_RES_ALLOSEG SEG, V_FDATE DAYS
WHERE ALLO.ALLOID = SEG.ALLOID
AND ALLO.ALLO_DATE IS NULL
AND ALLO.ALLOIND = 'A'
AND (DAYS.FDATE >= ALLO.SDATE AND DAYS.FDATE <= ALLO.EDATE AND
INSTR(ALLO.WEEKDAY, DAYS.WEEKDAY) > 0)
AND NOT EXISTS (SELECT subQuery.ALLOID
from T_RES_ALLO subQuery
where subQuery.ALLO_DATE = DAYS.FDATE
and subQuery.ALLOTMENT = ALLO.ALLOTMENT)