Home > Ask the Oracle Experts > (Archive) Database Performance Tuning Questions & Answers > Full table scan instead of range scan
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Full table scan instead of range scan

Paul Baumgartel EXPERT RESPONSE FROM: Paul Baumgartel

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 24 July 2006
I am a beginner in SQL tuning. I have tried to tune the following query. The following is the table structure.
attendancedata:-
CARD_ID       NOT NULL VARCHAR2(20) 
TRDATE        NOT NULL DATE
TRINTIME      DATE
TROUTTIME     DATE
STATE         CHAR(6)

employee_roster:-
ecode          not null varchar2(10)
roster_date    not null date 
shift_id       varchar2(10)

shift:-(SHIFT_ID IS THE PRIMARY KEY)
SHIFT_ID          NOT NULL VARCHAR2(10)
SHIFTSHORT_DESC   VARCHAR2(50)
START_FROM_TIME   DATE
START_TO_TIME     DATE
BREAK1_FROM_TIME  DATE 
BREAK1_TO_TIME    DATe
BREAK2_FROM_TIME  DATE
BREAK2_TO_TIME    DATE
SHIFT_DESC        VARCHAR2(100)
LATE_AFTER        DATE

EMPLOYEE:-
ECODE VARCHAR2(10) PRIMARY KEY,
CARD_NO VARCHAR2(10)/* THIS CARD_ID IS USED IN ATTENDANCEDATA) 
FNAME   VARCHAR2(50)
LANME   VARCHAR2(50)

explain plan for
select /*+ ordered */ a.fname || ' ' || a.lname
name,d.shift_id,c.trintime,c.trdate,
d.roster_date
from attendancedata c,employee_roster d,employee a,shift b 
where c.card_id=a.card_no and
d.ecode=a.ecode and
d.roster_date=c.trdate and
d.shift_id=b.shift_id and
c.trdate between '01-jun-05' and '12-jun-05'
AND d.roster_date between '01-jun-05' and '12-jun-05'

OPERATION            OPTIONS              OBJECT_NAME           ID
PARENT_ID       COST
-------------------- -------------------- -------------------- ---
--------- ----------
SELECT STATEMENT                                                 0 
67
NESTED LOOPS                                                     1
0         67
HASH JOIN                                                        2
1         67
TABLE ACCESS         FULL                 EMPLOYEE               3 
2          3
HASH JOIN                                                        4
2         63
TABLE ACCESS         FULL                 ATTENDANCEDATA         5
4         20
TABLE ACCESS         FULL                 EMPLOYEE_ROSTER        6 
4         43
INDEX                UNIQUE SCAN          PK_SHIFT_ID            7
1          0

8 rows selected.
I have used TRDATE COLUMN of ATTENDANCEDATA but why is a full table scan happening instead of range scan? The same thing happens for the EMPLOYEE_ROSTER table -- why? Can you explain or suggest any other table access path? Statistics are gathered for ATTENDANCEDATA and EMPLOYEE_ROSTER.

>
EXPERT RESPONSE
Your query uses a character string value for TRDATE, whose datatype is DATE; Oracle performs an implicit datatype conversion, which means that the index can't be used. Change the last clause in your query to
c.trdate between to_date('01-jun-05','dd-mon-yy') 
and to_date('12-jun-05','dd-mon-yy')
AND d.roster_date between to_date('01-jun-05','dd-mon-yy') 
and to_date('12-jun-05','dd-mon-yy') 


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
(Archive) Database Performance Tuning
How tkprof works for tuning
Import of dump file took 20 hours
Optimize SQL query on table with 50 million records
Windows reporting high number of handles for oracle.exe processes
Performance problems in Unix vs. Windows
Insertion speed goes down with context index
Buffer busy waits on primary key index
Do indexes affect performance of updates and inserts?
Creating partitions on fastest area of disk
Slow queries on table; can't create index

Oracle database performance problems and tuning
Oracle 11g data compression
Varchar or number for better performance?
Do statistics on SYS-owned objects hurt performance in 10g?
Inside the Oracle 11g SQL Performance Advisor, part 1
Inside the Oracle 11g SQL Performance Advisor, part 2
Difference between driving table and driver table in Oracle
Best design for E-Business Suite on hard drive
20GB data dictionary causing performance problems
Using the cost-based optimizer to improve Database 10g performance
Online tablespace reorganization in Oracle 9i

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts