oracle - How to optimise this SQL Query -


this query taking more 4 minutes , want make run more quickly. please provide suggestions

select * fact_acct zz zz.c_acctschema_id=1000000 , zz.postingtype      ='a' , trunc(zz.dateacct,'dd') between to_date('2016-01-01','yyyy-mm-dd') , to_date('2016-01-01','yyyy-mm-dd') , z_id_cpt_to_val(account_id) <= z_id_cpt_to_val(1001508) , z_id_cpt_to_val(account_id) >= z_id_cpt_to_val(1001508)  

the function z_id_cpt_to_val () cause of problem, it's run in sql queries, take long time

because if retire last 2 lines ,this sql give results in 3 secondes

so, ideas optimise that

thanks

without plan , ddl on table assumption.

first assumption

you have index on fact_acct.dateacct, trunc(fact_acct.dateacct,'dd') - not use index trunc(fact_acct.dateacct,'dd') trim hour/ minutes/ seconds part. can use

zz.dateacct >= between to_date('2016-01-01','yyyy-mm-dd') <to_date('2016-01-02','yyyy-mm-dd') 

second assumption

instead of

z_id_cpt_to_val(account_id) <= z_id_cpt_to_val(1001508) 

put

 (select z_id_cpt_to_val(account_id) dual) <= (select z_id_cpt_to_val(1001508) dual) 

oracle doesn't execute functions every time insted uses caching mechanism. carefull! if want oracle executes z_id_cpt_to_val, don't need approach


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -