Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Where is Oracle's Grid ? long
"Sybrand Bakker" <gooiditweg_at_sybrandb.demon.nl> wrote in message
news:u6d5vv8fbvgu42aeln6bbvf067mnvl1jal_at_4ax.com...
> On Wed, 31 Dec 2003 11:11:14 -0000, "Niall Litchfield" > <n-litchfield_at_audit-commission.gov.uk> wrote: > > > It seems to me > >that hints *are* commands (albeit they are checked for validity first). > > A hint is a hint is a hint. If CBO calculates a better access path > without using the hint, the hint will be ignored
The hint isn't ignored so far as I can tell, but it is evaluated before passing to the CBO for validity. The CBO will then in every case that I have tested limit the execution plans it considers according to the hint, it of course still picks the lowest cost plan, usually when people complain that the CBO is ignoring a valid hint they mean that they havent sufficiently constrained the CBO. An example test follows.
This is my test script. the idea is to see what the CBO picks and then hint it to reverse the order of the nested loops join. The first attempt specifying the appropriate use_nl hint fails. The second attempt succeeds. There are significant differences though.
In trace 1 the CBO considers (and rejects) sort merge and hash joins. In trace 2 these disappear but the join order remains the same only when I specify both the order and the join method does the CBO do what I am trying to tell it to do. However it definitely doesn't ignore the hint, but uses it to limit what access methods it will use.
In addition my understanding of plan stability is this (simplified a bit and it could of course be incorrect). Oracle calculates the hash value of the sql statement. it then looks in the OUTLN tables to see if it has a modified sql statement stored for that hash value and if so it passes that sql statement (packed with hints that effectively prescribe one path only) to the CBO. Now if this is correct AND it is correct that hints can be ignored I don't see how plan stability can work.
@spool_results hints_test
connect niall/niall
pause 'Drop tables if they exist'
drop table hint1;
drop table hint2;
pause 'Create 2 tables'
create table hint1 as select * from all_objects where rownum < 2;
create table hint2 as select * from all_objects;
pause 'Add primary keys'
alter table hint1 add constraint pk_hint1 primary key(object_id);
alter table hint2 add constraint pk_hint2 primary key(object_id);
pause 'get some stats'
exec dbms_stats.gather_table_stats('NIALL','HINT1',CASCADE => TRUE);
exec dbms_stats.gather_table_stats('NIALL','HINT2',CASCADE => TRUE);
alter session set tracefile_identifier='base_plan';
alter session set events '10053 trace name context forever, level 1';
alter session set events '10046 trace name context forever, level 1';
pause 'base plan'
select count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL';
alter session set tracefile_identifier='hinted plan';
select /*+ use_nl(hint2 hint1) */ count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL';
alter session set tracefile_identifier='full hinted plan';
select /*+ordered use_nl(hint2 hint1) */ count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL';
alter session set events '10053 trace name context off';
spool off
The trace files that are generated look like this (optimizer parameters snipped)
base_plan
QUERY
select count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL'
Column: OBJECT_ID Col#: 4 Table: HINT1 Alias: HINT1 NDV: 1 NULLS: 0 DENS: 1.0000e+000 LO: 17867 HI: 17867NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OBJECT_ID Col#: 4 Table: HINT2 Alias: HINT2 NDV: 30328 NULLS: 0 DENS: 3.2973e-005 LO: 3 HI: 32446NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OWNER Col#: 1 Table: HINT2 Alias: HINT2 NDV: 27 NULLS: 0 DENS: 3.7037e-002 NO HISTOGRAM: #BKT: 1 #VAL: 2 TABLE: HINT2 ORIG CDN: 30328 ROUNDED CDN: 1123 CMPTD CDN: 1123Access path: tsc Resc: 22 Resp: 22 BEST_CST: 22.00 PATH: 2 Degree: 1
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 0.0000e+000 TB_SEL: 1.0000e+000
Access path: iff Resc: 2 Resp: 2
Access path: index (no sta/stp keys)
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 1.0000e+000 TB_SEL: 1.0000e+000
BEST_CST: 2.00 PATH: 4 Degree: 1
Index: PK_HINT2
TABLE: HINT2
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 8.9047e-004 TB_SEL: 8.9047e-004
Join (ordered NL): resc: 2 resp: 2
OPTIMIZER PERCENT INDEX CACHING = 80
Access path: index (eq-unique)
Index: PK_HINT2
TABLE: HINT2
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 0.0000e+000 TB_SEL: 0.0000e+000
Join (ordered NL): resc: 2 resp: 2
Join cardinality: 1 = outer (1) * inner (1123) * sel (8.8968e-004)
[flag=0]
Best NL cost: 3 resp: 2
SM Join
Outer table:
resc: 1 cdn: 1 rcz: 5 deg: 1 resp: 1
Inner table: HINT2
resc: 22 cdn: 1123 rcz: 11 deg: 1 resp: 22
using join:1 distribution:2 #groups:1
SORT resource Sort statistics Sort width: 2 Area size: 131072 Max Area size: 1257472 Degree: 1 Blocks to Sort: 2 Row size: 23 Rows: 1123 Initial runs: 1 Merge passes: 1 IO Cost / pass: 3 Total IO sort cost: 3 Total CPU sort cost: 0 Total Temp space used: 0
hash_area: 28 (max=154) buildfrag: 1 probefrag: 2ppasses: 1
Join result: cost: 3 cdn: 1 rcz: 16 Best so far: TABLE#: 0 CST: 2 CDN: 1 BYTES: 5 Best so far: TABLE#: 1 CST: 3 CDN: 1 BYTES: 16 ***********************
FETCH #1:c=0,e=92,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=4,tim=9629795399 FETCH #1:c=0,e=2,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=9629795802 STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=4 r=0 w=0time=81 us)'
hinted plan looks like
QUERY
select /*+ use_nl(hint2 hint1) */ count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL'
Column: OBJECT_ID Col#: 4 Table: HINT1 Alias: HINT1 NDV: 1 NULLS: 0 DENS: 1.0000e+000 LO: 17867 HI: 17867NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OBJECT_ID Col#: 4 Table: HINT2 Alias: HINT2 NDV: 30328 NULLS: 0 DENS: 3.2973e-005 LO: 3 HI: 32446NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OWNER Col#: 1 Table: HINT2 Alias: HINT2 NDV: 27 NULLS: 0 DENS: 3.7037e-002 NO HISTOGRAM: #BKT: 1 #VAL: 2 TABLE: HINT2 ORIG CDN: 30328 ROUNDED CDN: 1123 CMPTD CDN: 1123Access path: tsc Resc: 22 Resp: 22 BEST_CST: 22.00 PATH: 2 Degree: 1
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 0.0000e+000 TB_SEL: 1.0000e+000
Access path: iff Resc: 2 Resp: 2
Access path: index (no sta/stp keys)
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 1.0000e+000 TB_SEL: 1.0000e+000
BEST_CST: 2.00 PATH: 4 Degree: 1
Index: PK_HINT2
TABLE: HINT2
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 8.9047e-004 TB_SEL: 8.9047e-004
Join (ordered NL): resc: 2 resp: 2
OPTIMIZER PERCENT INDEX CACHING = 80
Access path: index (eq-unique)
Index: PK_HINT2
TABLE: HINT2
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 0.0000e+000 TB_SEL: 0.0000e+000
Join (ordered NL): resc: 2 resp: 2
Join cardinality: 1 = outer (1) * inner (1123) * sel (8.8968e-004)
[flag=0]
Best NL cost: 3 resp: 2
Join result: cost: 3 cdn: 1 rcz: 16 Best so far: TABLE#: 0 CST: 2 CDN: 1 BYTES: 5 Best so far: TABLE#: 1 CST: 3 CDN: 1 BYTES: 16 ***********************
FETCH #1:c=0,e=90,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=4,tim=9629817136 FETCH #1:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=9629817549 STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=4 r=0 w=0time=79 us)'
and finally
QUERY
select /*+ordered use_nl(hint2 hint1) */ count(*)
from hint2,hint1
where hint1.object_id=hint2.object_id
and hint2.owner='NIALL'
Column: OBJECT_ID Col#: 4 Table: HINT1 Alias: HINT1 NDV: 1 NULLS: 0 DENS: 1.0000e+000 LO: 17867 HI: 17867NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OBJECT_ID Col#: 4 Table: HINT2 Alias: HINT2 NDV: 30328 NULLS: 0 DENS: 3.2973e-005 LO: 3 HI: 32446NO HISTOGRAM: #BKT: 1 #VAL: 2
Column: OWNER Col#: 1 Table: HINT2 Alias: HINT2 NDV: 27 NULLS: 0 DENS: 3.7037e-002 NO HISTOGRAM: #BKT: 1 #VAL: 2 TABLE: HINT2 ORIG CDN: 30328 ROUNDED CDN: 1123 CMPTD CDN: 1123Access path: tsc Resc: 22 Resp: 22 BEST_CST: 22.00 PATH: 2 Degree: 1
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 0.0000e+000 TB_SEL: 1.0000e+000
Access path: iff Resc: 2 Resp: 2
Access path: index (no sta/stp keys)
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 1
IX_SEL: 1.0000e+000 TB_SEL: 1.0000e+000
BEST_CST: 2.00 PATH: 4 Degree: 1
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 2
IX_SEL: 0.0000e+000 TB_SEL: 1.0000e+000
Inner table: HINT1
Access path: iff Resc: 2
Join: Resc: 2268 Resp: 2268
OPTIMIZER PERCENT INDEX CACHING = 80
Access path: index (unique)
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 0
IX_SEL: 1.0000e+000 TB_SEL: 1.0000e+000
Join: resc: 23 resp: 23
OPTIMIZER PERCENT INDEX CACHING = 80
Access path: index (eq-unique)
Index: PK_HINT1
TABLE: HINT1
RSC_CPU: 0 RSC_IO: 0
IX_SEL: 0.0000e+000 TB_SEL: 0.0000e+000
Join: resc: 23 resp: 23
Join cardinality: 1 = outer (1123) * inner (1) * sel (8.8968e-004)
[flag=0]
Best NL cost: 24 resp: 23
Join result: cost: 24 cdn: 1 rcz: 16 Best so far: TABLE#: 0 CST: 22 CDN: 1123 BYTES: 12353 Best so far: TABLE#: 1 CST: 24 CDN: 1 BYTES: 16Final:
#1:c=10014,e=158659,p=123,cr=212,cu=0,mis=0,r=1,dep=0,og=4,tim=9629998690 FETCH #1:c=0,e=2,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=9629999363 STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=212 r=123 w=0time=158645 us)'