Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 2nd, 2005, 09:56 AM
fkoskotas fkoskotas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 56 fkoskotas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 26 m 16 sec
Reputation Power: 5
prevent a full table scan

how can i prevent a full table scan with this query:

1 select /*+ index (wip_event_log_idx1) */ min(track_id) as BeginId, max(track_id) as EndId from wip_event_log
2* where build_id = '4321'
l06db > /

BEGINID ENDID
---------------- ----------------
LDAA140001 LDAA140005

Elapsed: 00:00:55.67

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Cost=1862 Optimizer=RULE
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'WIP_EVENT_LOG'


Statistics
----------------------------------------------------------
1036 recursive calls
0 db block gets
21272 consistent gets
18115 physical reads
6992 redo size
224 bytes sent via SQL*Net to client
335 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
28 sorts (memory)
0 sorts (disk)
1 rows processed

Reply With Quote
  #2  
Old June 2nd, 2005, 04:29 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 17 m 10 sec
Reputation Power: 48
build_id has to be an indexed column, which it must be if you hinted the select statement that way. you're sure it is indexed (if it's 8.x Oracle it has to be the first column in the index ).

But the optimizer may use a full table scan if the entry occurs lots of times in the table. Remember, it is just a hint.

Try ANALYZE TABLE COMPUTE STATISTICS wip_event_log or ask your DBA to do it

Then change your hint to /*+ CHOOSE */
and see if things get better.

But remember, once you run a query, the results for the query are cached so run #2 can be a lot faster than run #1.

If it is NOT a production system get the DBA to run ALTER SYSTEM FLUSH SHARED POOL - this will wreck perfomance for anyone else using the same instance. But it does clear the cache, so you can compare test runs of your queries.

Reply With Quote
  #3  
Old June 3rd, 2005, 02:03 AM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,005 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 33 m 53 sec
Reputation Power: 67
How big is the table (in terms of rows)?
For smaller tables (< 5000 rows) it might actually be faster to do a full table scan then bothering with the index.

Secondly (not sure about that), an index on track_id might as well help.

Reply With Quote
  #4  
Old June 3rd, 2005, 02:27 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,906 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 6 h 56 m 54 sec
Reputation Power: 279
Why are you using the old RULE based optimizer? Read this (.doc) about the new COST based optimizer and it's tuning (i.e. why it chooses full table scans over indexes).
Also show us the table's DDL and index definition, plus the number of rows.
Follow jim mcnamara's advice, update statistics, and try different hints, I've had good results with FIRST_ROWS.
Here you can find some more informations about hints, but there is a ton of articles around.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > prevent a full table scan


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway