473,480 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 15520

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
3108
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
5877
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
8183
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
5654
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
6332
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
16277
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
2698
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
3184
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
377
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
7037
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
7032
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,...
1
6730
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
6873
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...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.