不同的执行时间与日期硬编码或不在oracle查询上

时间:2015-06-30 01:21:09

标签: oracle oracle11g

我有这个问题:

select  PROP_CREATED_DATE , 
    TVS_CHANNEL.TVS_DESCRIPTION CHANNEL, 
    CASE OVM_CATEGORY   WHEN '9'  then 'BIKE'
                        WHEN '10' then 'BIKE'
                        WHEN '11' then 'BIKE'
                        ELSE 'CAR'
        END AS PRODUCT, TVS_ACTION.TVS_DESCRIPTION BROKER, APV_ACTION_REFERENCE
from ad_proposals
inner join ad_proposal_versions on PROP_REFERENCE = APV_PROP_REFERENCE  
inner join ad_proposal_objects  on POB_APV_PROP_REFERENCE = APV_PROP_REFERENCE 
                            and POB_APV_VERSION_NUMBER = APV_VERSION_NUMBER
inner join ov_motors    on OVM_OBJ_ID = POB_OVM_OBJ_ID
                    and POB_OVM_NUMBER = OVM_NUMBER 
INNER JOIN table_values TVS_CHANNEL on TVS_CHANNEL.TVS_CODE = PROP_CHANNEL and TVS_CHANNEL.TVS_TAD_CODE = 'CHANNEL'
left outer join table_values TVS_ACTION on TVS_ACTION.TVS_CODE = APV_ACTION_REFERENCE and TVS_ACTION.TVS_TAD_CODE = 'EBROKERID'
where APV_CREATED_DATE >= add_months(trunc(sysdate),-1)
and APV_VERSION_NUMBER = 1 
and APV_ORIGIN_TYPE = 'NBV'

这并不是很复杂,但我面临一个我不明白的问题。 看到这一行 where APV_CREATED_DATE >= add_months(trunc(sysdate),-1)

如果我按where APV_CREATED_DATE >= DATE '2015-05-31'更改它,我的结果几乎是即时的,APV_CREATED_DATE上有一个索引,它是一个日期列。 但是使用函数add_months(trunc(sysdate),-1),我运行查询并获得任何答案,即使我等了一个小时......

计划的唯一区别在于:

INDEX RANGE SCAN INDEX JAPHONIE.AD_PROPOSAL_VERSIONS_IDX5;  Optimizer=Analyzed;  Search_columns=1;  Cost=1;  Cardinality=2;  Cpu_cost=8,666;  Io_cost=1;  Access_predicates="ad_proposal_versions"."apv_created_date">=add_months(trunc(sysdate@!),-1);  Time=1             
INDEX RANGE SCAN INDEX JAPHONIE.AD_PROPOSAL_VERSIONS_IDX5;  Optimizer=Analyzed;  Search_columns=1;  Cost=1;  Cardinality=2;  Cpu_cost=8,666;  Io_cost=1;  Access_predicates="ad_proposal_versions"."apv_created_date">=to_date(' 2015-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss');  Time=1

如果你有任何想法,我可以使这个查询有效,那就太棒了

0 个答案:

没有答案