提高oracle中的sql查询性能

时间:2014-03-13 12:17:39

标签: sql oracle

我现有的查询如下:

SELECT p.subcode as proc_subcode,
       r.subcode as rv_subcode,
       r.rlv,
       f.cfid,
       f.geozip,
       p.proc,
       p.sh_descr,
       f.begproc,
       f.endproc,
       p.descr,
       r.modi,
       f.per25
  FROM user.code p, user.relative r, user.frequency f
 WHERE f.ID = 'XOF'
   AND f.GEOZIP = '200'
   AND f.REL_DATE = '10-SEP-13'
   AND p.proc IN ('A0021', 'A0080', 'A0090', 'A0100', 'A0110', 'A0120',
        'A0130', 'A0140', 'A0160', 'A0170', 'A0180', 'A0190',
        'A0200', 'A0210', 'A0225')
   AND r.ID = f.ID
   AND f.REL_DATE = r.REL_DATE
   AND f.ID = p.ID
   AND f.REL_DATE = p.REL_DATE
   AND p.proc = r.proc
   AND p.proc between f.begproc AND f.endproc
   AND (('A0021' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0021' AND
       r.PROC = 'A0021' AND f.CFID = '00') OR
       ('A0080' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0080' AND
       r.PROC = 'A0080' AND f.CFID = '00') OR
       ('A0090' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0090' AND
       r.PROC = 'A0090' AND f.CFID = '00') OR
       ('A0100' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0100' AND
       r.PROC = 'A0100' AND f.CFID = '00') OR
       ('A0110' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0110' AND
       r.PROC = 'A0110' AND f.CFID = '00') OR
       ('A0120' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0120' AND
       r.PROC = 'A0120' AND f.CFID = '00') OR
       ('A0130' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0130' AND
       r.PROC = 'A0130' AND f.CFID = '00') OR
       ('A0140' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0140' AND
       r.PROC = 'A0140' AND f.CFID = '00') OR
       ('A0160' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0160' AND
       r.PROC = 'A0160' AND f.CFID = '00') OR
       ('A0170' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0170' AND
       r.PROC = 'A0170' AND f.CFID = '00') OR
       ('A0180' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0180' AND
       r.PROC = 'A0180' AND f.CFID = '00') OR
       ('A0190' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0190' AND
       r.PROC = 'A0190' AND f.CFID = '00') OR
       ('A0200' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0200' AND
       r.PROC = 'A0200' AND f.CFID = '00') OR
       ('A0210' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0210' AND
       r.PROC = 'A0210' AND f.CFID = '00') OR
       ('A0225' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0225' AND
       r.PROC = 'A0225' AND f.CFID = '00'))
 ORDER BY p.proc, r.modi, f.REL_DATE asc

上面的查询效果很好,但是,我计划在范围内添加100个p.proc,例如。它就像A0021-A1000。所以,我想提高sql查询性能。

有人可以帮忙吗?

编辑1:

我想可能的解决方案是删除p.proc的IN子句并使用它们之间。我不确定最后的AND条件。

编辑2:

查询说明

我基本上使用geozip并传递代码来获取特定区域的所有医疗费用,例如。 A0021意味着手术代码& 200意味着纽约& 2013年9月10日是发布日期并获得名为XOF的产品的结果。

1 个答案:

答案 0 :(得分:1)

首先

 WHERE f.ID = 'XOF'
   AND f.GEOZIP = '200'
   AND f.REL_DATE = '10-SEP-13'
   AND p.proc IN ('A0021', 'A0080', 'A0090', 'A0100', 'A0110', 'A0120',
        'A0130', 'A0140', 'A0160', 'A0170', 'A0180', 'A0190',
        'A0200', 'A0210', 'A0225')
   AND r.ID = f.ID
   AND f.REL_DATE = r.REL_DATE
   AND f.ID = p.ID
   AND f.REL_DATE = p.REL_DATE
   AND p.proc = r.proc
   AND p.proc between f.begproc AND f.endproc
   AND (('A0021' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0021' AND
       r.PROC = 'A0021' AND f.CFID = '00') OR
       ('A0080' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0080' AND
       r.PROC = 'A0080' AND f.CFID = '00') OR
       ('A0090' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0090' AND
       r.PROC = 'A0090' AND f.CFID = '00') OR....
查询中的

p.proc = r.proc。所以你不需要每次都在这些陈述中写它:

 ('A0090' BETWEEN f.BEGPROC AND f.ENDPROC AND p.PROC = 'A0090' AND
   r.PROC = 'A0090' AND f.CFID = '00') OR
所有这些陈述中的

也是f.CFID ='00'。您无需在每个语句中编写它。目前我认为您需要的只是:

WHERE f.ID = 'XOF'
       AND f.GEOZIP = '200'
       AND f.REL_DATE = '10-SEP-13'
       AND p.proc IN ('A0021', 'A0080', 'A0090', 'A0100', 'A0110', 'A0120',
            'A0130', 'A0140', 'A0160', 'A0170', 'A0180', 'A0190',
            'A0200', 'A0210', 'A0225')
       AND r.ID = f.ID
       AND f.REL_DATE = r.REL_DATE
       AND f.ID = p.ID
       AND f.REL_DATE = p.REL_DATE
       AND p.proc = r.proc
       AND p.proc between f.begproc AND f.endproc
       AND f.CFID='00'

这4个陈述

           AND p.proc IN ('A0021', 'A0080', 'A0090', 'A0100', 'A0110', 'A0120',
                'A0130', 'A0140', 'A0160', 'A0170', 'A0180', 'A0190',
                'A0200', 'A0210', 'A0225')
           AND p.proc = r.proc
           AND p.proc between f.begproc AND f.endproc
           AND f.CFID='00'

使所有这些BETWEEEN语句相同。

请检查您对数据的查询