473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sql using full table scan instead of an index

Hi Everyone,
I'm having trouble convincing myself that Oracle is executing a query
of mine as efficiently as possible, and I'm looking for a little
guidance.

The situation is pretty simple. I just have two tables, PARENT and
CHILD.

PARENT(
pkey int primary key,
value int,
vdate date
)

CHILD(
pkey int references PARENT(pkey),
cdata VARCHAR2
)

In this simple example, I have indices on every column except cdata.
The query is:

select CHILD.*
from CHILD, PARENT
where PARENT.value=100
and CHILD.pkey=PARENT.pkey
and PARENT.vdate between date1 and date2

An explain plan shows that this query always does a FTS on CHILD, and
I can't really see why. I guess I don't really understand the
optimizer well, but it would seem like a FTS isn't necessary because
of the index on CHILD.pkey. In fact, if I change the * to just
CHILD.pkey, the index is used as expected.

This is in Oracle 9.2.0.3. Both tables and all their indices have been
analyzed, and CHILD has approximately 1M rows in it, while PARENT has
about 200K. The whole thing's running on Windows 2000.

I'd appreciate any insights you may have,
ry
Jul 19 '05 #1
4 15516

Try giving it a HINT:


select /*+ INDEX(CHILD pkey) */ CHILD.*
from CHILD, PARENT
where PARENT.value=100
and CHILD.pkey=PARENT.pkey
and PARENT.vdate between date1 and date2;
--
Posted via http://dbforums.com
Jul 19 '05 #2
evidently the optimizer has decided the full table scan is faster than the
indexes for this query

your selection criteria is on the smaller table -- the traditional rule of
thumb for using an index is 2% or less of rows returned. likely, your
parent.value and parent.vdate predicates are not very selective

oracle is pretty fast at full table scans, all things being equal, with
multiblock reads and such.

consider how you'd have to do this 'manually' -- is i'm looking for a
reasonable large number of occurrences of a value in a book, do i want to
flip thru the pages (since i'm a good speed reader) or do i want to flip
back and forth from the index, often visiting the same page (i.e. data
block) multiple times

if you had some selection criteria on the CHILD table, you'd more likely see
index usage

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048
"ryan" <ry*******@yahoo.com> wrote in message
news:29**************************@posting.google.c om...
Hi Everyone,
I'm having trouble convincing myself that Oracle is executing a query
of mine as efficiently as possible, and I'm looking for a little
guidance.

The situation is pretty simple. I just have two tables, PARENT and
CHILD.

PARENT(
pkey int primary key,
value int,
vdate date
)

CHILD(
pkey int references PARENT(pkey),
cdata VARCHAR2
)

In this simple example, I have indices on every column except cdata.
The query is:

select CHILD.*
from CHILD, PARENT
where PARENT.value=100
and CHILD.pkey=PARENT.pkey
and PARENT.vdate between date1 and date2

An explain plan shows that this query always does a FTS on CHILD, and
I can't really see why. I guess I don't really understand the
optimizer well, but it would seem like a FTS isn't necessary because
of the index on CHILD.pkey. In fact, if I change the * to just
CHILD.pkey, the index is used as expected.

This is in Oracle 9.2.0.3. Both tables and all their indices have been
analyzed, and CHILD has approximately 1M rows in it, while PARENT has
about 200K. The whole thing's running on Windows 2000.

I'd appreciate any insights you may have,
ry

Jul 19 '05 #3
ry*******@yahoo.com (ryan) wrote in message news:<29**************************@posting.google. com>...
Hi Everyone,
I'm having trouble convincing myself that Oracle is executing a query
of mine as efficiently as possible, and I'm looking for a little
guidance.

The situation is pretty simple. I just have two tables, PARENT and
CHILD.

PARENT(
pkey int primary key,
value int,
vdate date
)

CHILD(
pkey int references PARENT(pkey),
cdata VARCHAR2
)

In this simple example, I have indices on every column except cdata.
The query is:

select CHILD.*
from CHILD, PARENT
where PARENT.value=100
and CHILD.pkey=PARENT.pkey
and PARENT.vdate between date1 and date2

An explain plan shows that this query always does a FTS on CHILD, and
I can't really see why. I guess I don't really understand the
optimizer well, but it would seem like a FTS isn't necessary because
of the index on CHILD.pkey. In fact, if I change the * to just
CHILD.pkey, the index is used as expected.

This is in Oracle 9.2.0.3. Both tables and all their indices have been
analyzed, and CHILD has approximately 1M rows in it, while PARENT has
about 200K. The whole thing's running on Windows 2000.

I'd appreciate any insights you may have,
ry


Ryan, it would have been nice to see the actual explain plan. I am
not sure from your post if Oracle is driving on the child table or
performing the FTS in a loop.

Based on the way the query is written I would guess that Oracle should
drive on the Parent table entering it with either the index on value
or the index on the date range. Value appears to be a constant. If
this is true and if 100 is selective then a histogram on this column
might be useful if Oracle did not chose to drive on this. The access
by vdate would appear to use bind variables so Oracle does not know
what percentage of the table will have to be scanned.

You did not tell us what type of join Oracle chose to do? Did Oracle
chose a hash join? That would pretty much require a FTS of child if
Oracle drove on Parent.

HTH -- Mark D Powell --
Jul 19 '05 #4
ry*******@yahoo.com (ryan) wrote in message news:<29**************************@posting.google. com>...
Hi Everyone,
I'm having trouble convincing myself that Oracle is executing a query
of mine as efficiently as possible, and I'm looking for a little
guidance.

The situation is pretty simple. I just have two tables, PARENT and
CHILD.

PARENT(
pkey int primary key,
value int,
vdate date
)

CHILD(
pkey int references PARENT(pkey),
cdata VARCHAR2
)

In this simple example, I have indices on every column except cdata.
The query is:

select CHILD.*
from CHILD, PARENT
where PARENT.value=100
and CHILD.pkey=PARENT.pkey
and PARENT.vdate between date1 and date2

An explain plan shows that this query always does a FTS on CHILD, and
I can't really see why. I guess I don't really understand the
optimizer well, but it would seem like a FTS isn't necessary because
of the index on CHILD.pkey. In fact, if I change the * to just
CHILD.pkey, the index is used as expected.

This is in Oracle 9.2.0.3. Both tables and all their indices have been
analyzed, and CHILD has approximately 1M rows in it, while PARENT has
about 200K. The whole thing's running on Windows 2000.

I'd appreciate any insights you may have,
ry

Hi again,
Thanks for all the advice. My solution to the problem was to add a
hint forcing the index on CHILD.pkey to be used. Deleting the
statistics on the table had the same effect. I'm just starting the
load process, and it's also possible that my selection criteria wasn't
selective enough. Once I get more data in the tables, I re-enable the
CBO and see if it does a better job. Until then, thanks again,

ry
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carlos Ibarra | last post by:
In various places I have seen mentioned the importance of indexing foreign keys to avoid table locks on the child table on parent update/delete and full table scans when the constraint has action...
3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
6
by: talfano | last post by:
Hello, We are having a very strange problem. We have a table with about 5 million rows in it. The problem is with one of the non clustered indexes. I have noticed that sometimes in query...
13
by: LUIS FAJARDO | last post by:
I have the following sintax: Select * From Inventory Where PartId = Coalesce(v_PartId, PartId) this type of query is used within an store procedure that provide the v_PartId parameter, the...
2
by: db2udbgirl | last post by:
If I perform a select count(*) from tred.order_delivery query will it internally perform a full table scan to determine the row count for the following scenario case 1: There is a primary key on a...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
1
by: shilpasharma | last post by:
Hi, Can anybody let me know how I can optimise following Query. Select * from reports where ( exists ( SELECT 1 FROM results_required rr, item_claims_trials ict, results res WHERE...
1
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the...
4
by: ryan | last post by:
Hi Everyone, I'm having trouble convincing myself that Oracle is executing a query of mine as efficiently as possible, and I'm looking for a little guidance. The situation is pretty simple. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.