Function based indexes? 2005-12-06 - By Wolfgang Breitling
David and all, this is why cursor_sharing != exact will make a difference: 20:01:55 ora92.scott> alter session set cursor_sharing=force; Session altered. 20:02:31 ora92.scott> alter session set events '10046 trace name context forever'; Session altered. 20:05:50 ora92.scott> alter session set events '10046 trace name context forever, level 4'; Session altered. 20:06:00 ora92.scott> select count(t) from dmk where a = 1; COUNT(T) -- ---- -- 30000 1 row selected. 20:06:17 ora92.scott> select count(t) from dmk where a = 0; COUNT(T) -- ---- -- 2 1 row selected. 20:06:18 ora92.scott> select count(t) from dmk where case a when 0 then 0 end = 0; COUNT(T) -- ---- -- 2 1 row selected. 20:06:18 ora92.scott> select hash_value, sql_text from v$sql where sql_text like 'select count(%) from dmk%'; HASH_VALUE SQL_TEXT -- ---- -- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- - 1544817296 select count(t) from dmk where a = :"SYS_B_0" 2741099339 select count(t) from dmk where case a when :"SYS_B_0" then :"SYS_B_1" end = :"SYS_B_2" 2 rows selected. 20:07:42 ora92.scott> @(protected) 1544817296 cn plan hash ELAPSED CPU exec LIO PIO rows SQL_TEXT --- -- ---- -- -- ---- --- -- ---- --- -- ----- -- ---- ------ -- ---- --- -- ---- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ 0 3494866697 0.202 0.135 2 3,584 198 2 select count(t) from dmk where a = :"SYS_B_0" id cost CARD operation ROWS ELAPSED CR_GETS CU_GETS READS WRITES -- --- -- --- -- ---- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- -- -- ---- --- -- ---- --- -- ---- --- -- ---- -- -- ---- 0 308 SELECT STATEMENT 1 1 SORT AGGREGATE 1 0.030 1,792 0 99 0 2F 308 15,001 TABLE ACCESS FULL DMK 2 0.030 1,792 0 99 0 id PREDICATES ---- -- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- 2 Filter= "DMK"."A"=:SYS_B_0 20:07:55 ora92.scott> @(protected) 2741099339 plan hash ELAPSED CPU exec LIO PIO rows SQL_TEXT -- ---- -- -- ---- --- -- ---- --- -- ----- -- ---- ------ -- ---- --- -- ---- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ 3494866697 0.064 0.040 1 1,792 99 1 select count(t) from dmk where case a when :"SYS_B_0" then :"SYS _B_1" end = :"SYS_B_2" id cost CARD operation ROWS ELAPSED CR_GETS CU_GETS READS WRITES -- --- -- --- -- ---- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- -- -- ---- --- -- ---- --- -- ---- --- -- ---- -- -- ---- 0 314 SELECT STATEMENT 1 1 SORT AGGREGATE 1 0.030 1,792 0 99 0 2F 314 300 TABLE ACCESS FULL DMK 2 0.030 1,792 0 99 0 id PREDICATES ---- -- ---- -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- 2 Filter= CASE "DMK"."A" WHEN :SYS_B_0 THEN :SYS_B_1 END =:SYS_B_2 20:08:05 ora92.scott> I deliberately did not use autotrace and got the plans from v$sql_plan in order to give bind variable peeking a chance to do its thing. Well, obviously it leaves something to be desired. At 06:46 PM 12/6/2005, David Kurtz wrote: >I am quite rightly taken to task. My example was produced on 9.2.0.5.0 on >Windows. >I used analyze because I was being lazy. However, I have now checked >dbms_stats on both 9.2.0.5 and 10.1.0.3 and got the same behaviour. > >But, why would cursor_sharing make any difference? Regards Wolfgang Breitling Centrex Consulting Corporation www.centrexcc.com -- http://www.freelists.org/webpage/oracle-l