help getting cost down in plan table?



Hello everyone. I think I need some guidance to get my query to use an
index. When I look at a plan table for a query I see "TABLE ACCESS
FULL" with bytes 186M.

-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1172K| 72M| 2775
(5)| 00:00:34 |
|* 1 | HASH JOIN | | 1172K| 72M| 2775
(5)| 00:00:34 |
| 2 | TABLE ACCESS FULL| TBL_FVALJOIN | 3 | 78 | 3
(0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| TBL_FVAL | 5007K| 186M| 2725
(3)| 00:00:33 |
-----------------------------------------------------------------------------------

The query performance is okay but I expected to see some index use
rather than "TABLE ACCESS FULL". Alternatively I don't understand what
the plan table is telling me so I would appreciate you telling too if
this is the case.

Table tbl_fval contains about 5million rows and table tbl_fvaljoin
contains a lot less (only contains 3 rows in the sample data below but
in our production system is contains a lot more). We are using Oracle
10.1.0.4 on Windows 2000 SP2. I have included the ddl to create the
tables, indexes etc, and the SQL to use the plan table. Am I missing
something to get the cost down (and reduce the 186M above)?

Thank you
Barry


create table tbl_fval(b_id number,b_fid number,b_fval number);
--
--and now insert lots and lots of data
--
create index idx_fval_id
on tbl_fval(b_id);
create index idx_fval_fid
on tbl_fval(b_fid);
create index idx_fval_fval
on tbl_fval(b_fval);


create table tbl_fvaljoin(b_fid number,b_fval number);
insert into tbl_fvaljoin values(100,10);
insert into tbl_fvaljoin values(101,12);
insert into tbl_fvaljoin values(103,150);

create index idx_fvaljoin_fid
on tbl_fvaljoin(b_fid);
create index idx_fvaljoin_fval
on tbl_fvaljoin(b_fval);


explain plan for
select t1.b_id
from tbl_fval t1,tbl_fvaljoin t2
where t1.b_fid=t2.b_fid
and t1.b_fval=t2.b_fval;

--
--this is the plan table shown at the start of the message
select plan_table_output from table(dbms_xplan.display);

.



Relevant Pages

  • Re: Why is this
    ... would be to have a single index on (lastrecon, acctnum, deposit) [or ... cover the query and handle the restrictive condition immediately. ... there is no perfect query plan. ... use the index for TOP 1, even if it used quite a few bookmark lookups, ...
    (microsoft.public.sqlserver.server)
  • Re: Query optimizer issue
    ... Consider a stored proc defined as follows: ... when compiling a plan. ... parameter @p1 into the query at compile time before a plan for the query ... execution plans, but a key requirement for everything to work as expected ...
    (microsoft.public.sqlserver.server)
  • Re: Execute SQL UD Function call timeout, 1-3 seconds in query ana
    ... We did build a little ASP.NET page yesterday that lets us put a given sql ... query into a text box and then return the execution plan (using Showplan_Text ... Query Analyzer. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Store procedure vs Direct statement ???
    ... Try opening up query analyzer and checking out the query plan or ... advantages of using stored procedures over not using stored procedures is the ... the better the overall performance of your SQL ... dynamic sql versus the execution plan for a stored procedure. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SP runs slower than same query in Query analyzer. Why??
    ... Andrew your reply was useful but I'm quite new to sql server and I'm ... query gives me the results in 3-4 seconds. ... > Keep in mind that the server has to compile a complete execution plan ... > when compiling a plan. ...
    (microsoft.public.sqlserver.clients)