473,796 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optimizing Sql - unable to use index

I need help trying to optimize a SQL query. I am using Oracle 8i.

I have a table with about 1.2 million records, lets call it T1. I am
doing a join from another table, lets say T2 which has a restriction
on it. T2's id is a foreign key on T1.

T1 also has a index on
T2id2T1id T1 (T1.t2Id, T1.id)

What happens is if I retrive just the T1.id from the query, it uses
the T2id2T1id index for a reverse walk. However as soon as I retrieve
some other column from T1, say T1.some_col, oracle decides to do a
full table scan of T1.

Even if I force an optimizer hint /*+ index (t1 t2id2t1id) */, it does
a full scan of this index.

Any clues to why oracle decides to do a full table scan on a
1.2million record table???
Jul 19 '05 #1
3 13920

"Haider Kazmi" <hk****@despamm ed.com> wrote in message
news:f1******** *************** ***@posting.goo gle.com...
I need help trying to optimize a SQL query. I am using Oracle 8i.

I have a table with about 1.2 million records, lets call it T1. I am
doing a join from another table, lets say T2 which has a restriction
on it. T2's id is a foreign key on T1.

T1 also has a index on
T2id2T1id T1 (T1.t2Id, T1.id)

What happens is if I retrive just the T1.id from the query, it uses
the T2id2T1id index for a reverse walk. However as soon as I retrieve
some other column from T1, say T1.some_col, oracle decides to do a
full table scan of T1.

Even if I force an optimizer hint /*+ index (t1 t2id2t1id) */, it does
a full scan of this index.

Any clues to why oracle decides to do a full table scan on a
1.2million record table???


Are the datatypes of the joined fields the same? If not that might be the
problem. Also is the table and indexes analyzed? Are you retrieving a
small percentage of the rows or something larger like 10% or more? (that can
cause a full table scan because it might be faster.)

What is the explain plan? What is the tkprof output?
Jim
Jul 19 '05 #2
hk****@despamme d.com (Haider Kazmi) wrote in message news:<f1******* *************** ****@posting.go ogle.com>...
I need help trying to optimize a SQL query. I am using Oracle 8i.

I have a table with about 1.2 million records, lets call it T1. I am
doing a join from another table, lets say T2 which has a restriction
on it. T2's id is a foreign key on T1.

T1 also has a index on
T2id2T1id T1 (T1.t2Id, T1.id)

What happens is if I retrive just the T1.id from the query, it uses
the T2id2T1id index for a reverse walk. However as soon as I retrieve
some other column from T1, say T1.some_col, oracle decides to do a
full table scan of T1.

Even if I force an optimizer hint /*+ index (t1 t2id2t1id) */, it does
a full scan of this index.

Any clues to why oracle decides to do a full table scan on a
1.2million record table???
Take a look at this article on setting the init.ora parameters
optimizer_index _cost_adj and optimizer_index _caching at
http://www.dbazine.com/jlewis12.shtml .

I ran the following, written based on my understanding of the above
article, through out a day without any values overriding the defaults
to get a guess for some 'good' initials settings. After bouncing the
instance users did see a significant improvement in search time
because indexes were used more frequently. When I ran the same
scripts after setting them the first time and trying the new values
the response was actually worse.

set linesize 50;
select to_char(sysdate ,'YYYY-MM-DD-HH24:MI:SS') from dual;
select 'optimizer_inde x_cost_adj='||t o_char(round(10 0*(max(seq)/max(scat))))
as "jlewis init.ora settings"
from (
select average_wait as "SEQ",0 as "SCAT" from v$system_event
where event = 'db file sequential read'
union all
select 0,average_wait from v$system_event
where event = 'db file scattered read'
)
union all
select 'optimizer_inde x_caching='||to _char(round(avg (cache_hit_rati o)))
from (
select (1-(phy.value/(cur.value+con. value)))*100 cache_hit_ratio
from v$sysstat cur
,v$sysstat con
,v$sysstat phy
where cur.name = 'db block gets'
and con.name = 'consistent gets'
and phy.name = 'physical reads'
and (1-(phy.value/(cur.value+con. value)))*100 > 0
union all
select (1-((phy.value-dir.value)/(cur.value+con. value)))*100
cache_hit_ratio
from v$sysstat cur
,v$sysstat con
,v$sysstat phy
,v$sysstat dir
where cur.name = 'db block gets'
and con.name = 'consistent gets'
and dir.name = 'physical reads direct'
and phy.name = 'physical reads'
and (1-((phy.value-dir.value)/(cur.value+con. value)))*100 > 0
union all
select (1-(physical_reads/
(decode(db_bloc k_gets+consiste nt_gets,0,.0000 000001,db_block _gets+consisten t_gets))))*100
cache_hit_ratio
from v$buffer_pool_s tatistics
where
(1-(physical_reads/
(decode(db_bloc k_gets+consiste nt_gets,0,.0000 000001,db_block _gets+consisten t_gets))))*100 0

);
Jul 19 '05 #3
Try something simple first.
If T1 and T2 have primary keys defined, and T2 has a FK to the PK of
T1, try DROPPING the combined index(es) first. Let the DB use PK's
only.
However, if you are trying to select other fields than the ones
indexed, it is normal for the DB to do a full table scan. Try a
COUNT(*) of the query. Does it run faster?
Post a script for the tables, PK's and FK's, and the query. It may
give us some more clues.

Cheers.
Jul 19 '05 #4

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

Similar topics

0
509
by: Eric B. | last post by:
Hi, I'm somewhat new to MySql. I've been using it for a while, but pretty much out of the box setup, and am starting to suffer heavily with my larger tables. I have a table with 5,000,000+ rows that I have to search and do joins on. Although I have an index set up for it, the joined select will still take some 400+ seconds to return, which is obviously unacceptable. This is due to enormous HD access. Perhaps someone can help me...
3
2423
by: Alexander Anderson | last post by:
I have a DELETE statement that deletes duplicate data from a table. It takes a long time to execute, so I thought I'd seek advice here. The structure of the table is little funny. The following is NOT the table, but the representation of the data in the table: +-----------+ | a | b | +-----+-----+ | 123 | 234 | | 345 | 456 |
6
2015
by: Uros | last post by:
Hello! I have some trouble getting good results from my query. here is structure stat_views id | integer id_zone | integer created | timestamp
16
4226
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the project in debug mode (by hitting F5) it gives an error message "Error while trying to run project: Unable to start debugging on the web server.
4
3497
by: Got2Go | last post by:
Hello Group, I have a table that has millions of records in it. About 100 records are added every 5 minutes (one per OIDID) (the sample provided below has data for 2 OIDIDs (99 and 100) And I have a webpage that executes 9 queries one after the other, and then displays the results on the webpage. When the database was empty, this process was very quick. But, as the DB grew, it became slower.
24
3169
by: Richard G. Riley | last post by:
Without resorting to asm chunks I'm working on a few small routines which manipulate bitmasks. I'm looking for any guidance on writing C in a manner which tilts the compilers hand in, if possible, a compiler/underlying processor independant way : althought to be fair I cant see this stuff on anything other than x86, but who knows. I found some ok info here: http://www.eventhelix.com/RealtimeMantra/Basics/OptimizingCAndCPPCode.htm...
1
1801
by: mamapossible | last post by:
Hi, I've spent hours trying to optimize this simple query: SELECT count(sites_jobs.id) as jobCount, sites_jobs_categories.frn_site_id, sites_jobs_categories.id, sites_jobs_categories.name, FROM sites_jobs_categories LEFT JOIN sites_jobs ON sites_jobs.frn_jobs_categories_id = sites_jobs_categories.id GROUP BY sites_jobs_categories.id HAVING sites_jobs_categories.frn_site_id = #request.siteId#
2
1101
by: Michael Hoffman | last post by:
The peephole optimizer now takes things like if 0: do_stuff() and optimizes them away, and optimizes away the conditional in "if 1:". What if I had a function like this? def func(debug=False):
3
501
by: Haider Kazmi | last post by:
I need help trying to optimize a SQL query. I am using Oracle 8i. I have a table with about 1.2 million records, lets call it T1. I am doing a join from another table, lets say T2 which has a restriction on it. T2's id is a foreign key on T1. T1 also has a index on T2id2T1id T1 (T1.t2Id, T1.id) What happens is if I retrive just the T1.id from the query, it uses
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.