Tom,
Thanks for your time !
This part doesn't compute on my machine :
SQL> connect /
ERROR:
ORA-01017: invalid username/password; logon denied
I allowed myself to modify the end of the script as follows :
-added a "set tab off" for nice formatting when pasting on your site
-added "as sysdba" and a "conn scott/tiger" after the shared_pool flush.
(hope this was what you intended)
The end of the script now looks like this :
connect /as sysdba
alter system flush shared_pool;
conn scott/tiger
alter session set use_stored_outlines=myol;
set serveroutput off
@q.sql
select * from table(dbms_xplan.display_cursor);
set autotrace traceonly explain
@q.sql
set autotrace off
I also had to grant 'select any dictionary' to scott to allow dbms_xplan.display_cursor to select from v$session.
Here's the output :
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 15 18:55:28 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set linesize 10000
SQL> drop table t purge;
drop table t purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> drop outline myol;
drop outline myol
*
ERROR at line 1:
ORA-18002: the specified outline does not exist
SQL>
SQL> column PLAN_TABLE_OUTPUT format a80 truncate
SQL>
SQL> create table T
2 (
3 c1 integer,
4 c2 integer,
5 c3 integer,
6 c4 integer,
7 c5 integer,
8 c6 integer,
9 c7 integer,
10 c8 date,
11 val1 varchar2(30),
12 val2 varchar2(30),
13 val3 varchar2(30),
14 val4 varchar2(30),
15 val5 varchar2(30),
16 val6 varchar2(30)
17 );
Table created.
SQL>
SQL> alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);
Table altered.
SQL>
SQL> create index T_idx on T(c6, c7);
Index created.
SQL>
SQL> insert into T
2 select
3 mod(n,97),
4 mod(n,89),
5 mod(n,83),
6 mod(n,79),
7 mod(n,73),
8 mod(n,67),
9 mod(n,61),
10 sysdate+(n/(24*3600)),
11 rpad('a',30,'a'),
12 rpad('a',30,'a'),
13 rpad('a',30,'a'),
14 rpad('a',30,'a'),
15 rpad('a',30,'a'),
16 rpad('a',30,'a')
17 from (
18 select level n from dual connect by level <= 1000
19 );
1000 rows created.
SQL> commit;
Commit complete.
SQL>
SQL> begin
2 dbms_stats.gather_table_stats(
3 ownname => user,
4 tabname => 'T',
5 method_opt => 'for all columns size 1',
6 estimate_percent => null,
7 cascade => true);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL>
SQL> @q.sql
SQL> select
2 c1, c2, c3, c4, c5, c6, c7, c8
3 , val1, val2, val3, val4, val5, val6
4 from T
5 where c1=19
6 and c2=54
7 and c3=28
8 and c4=41
9 and c5=16
10 and c6=51
11 and c7=18
12 and c8=(sysdate + 1.2345)
13 for update nowait;
no rows selected
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 0hp10pkdk56ky, child number 0
-------------------------------------
select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6
from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 and
c7=18 and c8=(sysdate + 1.2345) for update nowait
Plan hash value: 2503694904
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)|
| 1 | FOR UPDATE | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00
|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND
"C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
81)
24 rows selected.
SQL> alter index t_pk unusable;
Index altered.
SQL> @q.sql
SQL> select
2 c1, c2, c3, c4, c5, c6, c7, c8
3 , val1, val2, val3, val4, val5, val6
4 from T
5 where c1=19
6 and c2=54
7 and c3=28
8 and c4=41
9 and c5=16
10 and c6=51
11 and c7=18
12 and c8=(sysdate + 1.2345)
13 for update nowait;
no rows selected
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 0hp10pkdk56ky, child number 0
-------------------------------------
select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6
from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 and
c7=18 and c8=(sysdate + 1.2345) for update nowait
Plan hash value: 882521605
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)|
| 1 | FOR UPDATE | | | | |
|* 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:0
|* 3 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:0
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND
"C8"=SYSDATE@!+1.23450231481481481481481481481481481481))
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
3 - access("C6"=51 AND "C7"=18)
24 rows selected.
SQL>
SQL> create outline myol for category myol on
2 @q.sql
2 select
3 c1, c2, c3, c4, c5, c6, c7, c8
4 , val1, val2, val3, val4, val5, val6
5 from T
6 where c1=19
7 and c2=54
8 and c3=28
9 and c4=41
10 and c5=16
11 and c6=51
12 and c7=18
13 and c8=(sysdate + 1.2345)
14 for update nowait;
Outline created.
SQL>
SQL> alter index t_pk rebuild;
Index altered.
SQL>
SQL>
SQL>
SQL>
SQL> connect /as sysdba
Connected.
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> conn scott/tiger
Connected.
SQL>
SQL>
SQL> alter session set use_stored_outlines=myol;
Session altered.
SQL> set serveroutput off
SQL> @q.sql
SQL> select
2 c1, c2, c3, c4, c5, c6, c7, c8
3 , val1, val2, val3, val4, val5, val6
4 from T
5 where c1=19
6 and c2=54
7 and c3=28
8 and c4=41
9 and c5=16
10 and c6=51
11 and c7=18
12 and c8=(sysdate + 1.2345)
13 for update nowait;
no rows selected
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 0hp10pkdk56ky, child number 0
-------------------------------------
select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6
from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 and
c7=18 and c8=(sysdate + 1.2345) for update nowait
Plan hash value: 2503694904
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)|
| 1 | FOR UPDATE | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00
|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND
"C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
81)
Note
-----
- outline "MYOL" used for this statement
28 rows selected.
SQL> set autotrace traceonly explain
SQL> @q.sql
SQL> select
2 c1, c2, c3, c4, c5, c6, c7, c8
3 , val1, val2, val3, val4, val5, val6
4 from T
5 where c1=19
6 and c2=54
7 and c3=28
8 and c4=41
9 and c5=16
10 and c6=51
11 and c7=18
12 and c8=(sysdate + 1.2345)
13 for update nowait;
Execution Plan
----------------------------------------------------------
Plan hash value: 2503694904
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 214 | 2 (0)| 00:00
| 1 | FOR UPDATE | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00
|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND
"C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148
81)
Note
-----
- outline "MYOL" used for this statement
SQL> set autotrace off
SQL>
Still the strange behavior...
By the way, i had the opportunity to test it on another database (Linux OS too, same DB version) and it worked...
(of course, the test is not exactly the same as it is a true table with true data, and the query was using bind variables)
That would make me think the problem is with my "sandbox" db... I must have done something strange to it.
If I have time tomorrow, I'll create a brand new DB on the same system to see if this reproduces.