Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Need help identifying why my query is not using a unique index efficiently
I have a packaged application that generates a simple correlated
sub-query. The execution plan uses the unique index I want but not
efficiently. The access predicate information shows that only the first
column (Company) is used to navigate to the starting point in the index.
The second column (Part_id) has a filter applied to it even though it's
equi-joined to the results of the correlated sub-query into Part.
I produced this test scenario by trimming out the irrelevant stuff. It's a simple Item and Parts relationship in a multi-company warehouse. Items are made up of Parts. Items and Parts are owned by separate companies so everything is connected by the Company column as well as IDs. Any insight would be greatly appreciated.
Tony Aponte
Here's the script and plan output:
create table item (item_id number not null , company number not null , part_id number not null , quantity number);
alter table item add constraint item_pk primary key (company,part_id);
create table part(part_id number not null, company number not null , part_name varchar2(30) not null);
create unique index part_idx on part(company,part_name);
alter table part add constraint part_fk foreign key (company, part_id) references item (company, part_id) enable validate;
explain plan for
select /*+ first_rows */ *
from item i
where i.company = :b1
and i.part_id = (select part_id
from part p where p.company=i.company and part_name=:b2);select * from table(dbms_xplan.display);
| Id | Operation | Name | Rows | Bytes |Cost |
Predicate Information (identified by operation id):
2 - access("SYS_ALIAS_1"."COMPANY"=TO_NUMBER(:Z)) filter("SYS_ALIAS_1"."PART_ID"= (SELECT /*+ */ "P"."PART_ID" FROM "PART" "P" WHERE "P"."PART_NAME"=:Z AND"P"."COMPANY"=:B1))
Note: cpu costing is off
20 rows selected.
-- http://www.freelists.org/webpage/oracle-lReceived on Tue Apr 24 2007 - 16:04:52 CDT
![]() |
![]() |