Oracle simple Select query optimization -
i have below simple dynamic select query
select relationship dime_master cin=? , ssn=? , account_number=?
the table has 1,083,701 records. query takes 11 12 secs execute expensive. dime_master table has account, card_number indexes. please me optimize query query execution time under fraction of second.
look @ predicate information:
-------------------------------------- 1 - filter(to_number("dime_master"."ssn")=226550956 , to_number("dime_master"."account_number")=4425050005218650 , to_number("dime_master"."cin")=00335093464)
the type of columns nvarchar, parameters in query numbers.
oracle must cast numbers strings, not smart in casting.
oracles , fortune-tellers not right ;)
these casts prevents query using indices.
rewrite query using explicit conversion into:
select relationship dime_master cin=to_char(?) , ssn=to_char(?) , account_number=to_char(?)
then run command:
exec dbms_stats.gather_table_stats( user, 'dime_master' );
and run query , show new explain plan.
please not paste explain plans here, unreadable,
please use pastebin instead, , paste links here, thank you.
look @ simple example, shows why need explicit casts:
create table "dime_master" ( "account_number" nvarchar2(16) ); insert dime_master select round( dbms_random.value( 1, 100000 )) dual connect level <= 100000; commit; create index dime_master_acc_ix on dime_master( account_number ); explain plan select * dime_master account_number = 123; select * table( dbms_xplan.display ); plan hash value: 1551952897 --------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | --------------------------------------------------------------------------------- | 0 | select statement | | 3 | 54 | 70 (3)| 00:00:01 | |* 1 | table access full| dime_master | 3 | 54 | 70 (3)| 00:00:01 | --------------------------------------------------------------------------------- predicate information (identified operation id): --------------------------------------------------- 1 - filter(to_number("account_number")=123) explain plan select * dime_master account_number = to_char( 123 ); select * table( dbms_xplan.display ); plan hash value: 3367829596 --------------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | --------------------------------------------------------------------------------------- | 0 | select statement | | 3 | 54 | 1 (0)| 00:00:01 | |* 1 | index range scan| dime_master_acc_ix | 3 | 54 | 1 (0)| 00:00:01 | --------------------------------------------------------------------------------------- predicate information (identified operation id): --------------------------------------------------- 1 - access("account_number"=u'123')
Comments
Post a Comment