If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Table scan/Index scan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-06, 07:42
Luke Russell Luke Russell is offline
Registered User
 
Join Date: Jan 2006
Posts: 2
Table scan/Index scan

At the company I work job applicants are required to do a little exam.

The human resource manager recently had a candidate who claimed one of the questions was ambiguous.

The HRM asked me to look into the matter, but since I am no expert in the in the workings of DB2 I submit the question to you hoping any of you can give me a definitive answer.

The question on the exam is :

Code:
  
  Given a table PARTS with a primary key
     PARTNO    CHAR(15)

  A select 

     SELECT * FROM PARTS
     WHERE PARTNO = :WS-PART

  in which the host variable is declared as

     WS-PART   PIC X(12).
 
 This wil be executed using :
   1)  an index scan
   2)  a table scan
   3)  this will give a compilation error
The candidate claimed that a table scan was used prior to version 8 of DB2
while starting at version 8 an index scan is used.

Can anybody confirm this ??

Does anybody know of a manual or an other source of information from IBM where this is described ??


Your help is appreciated
Luke
Reply With Quote
  #2 (permalink)  
Old 01-13-06, 09:15
sun4u sun4u is offline
Registered User
 
Join Date: Dec 2005
Posts: 18
If Table has only one column PARTNO, it will be index scan but if table contains more columns then it will be first index scan then fetch/join to get other columns.
Reply With Quote
  #3 (permalink)  
Old 01-13-06, 09:22
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
the given SELECT may use an index independent of the DB2 version as the host variable is shorter than the column.
If the host variable is longer than the column, an index could only be used in version 8.

Of cource, a tablespace-scan can be chosen nevertheless ( e.g. if RUNSTATS indicates, that the table is empty ...)
Reply With Quote
  #4 (permalink)  
Old 01-13-06, 10:12
Luke Russell Luke Russell is offline
Registered User
 
Join Date: Jan 2006
Posts: 2
The question really was if the behaviour of DB2 has changed between version 7 and version 8.
My HRM always counts "table scan" as the right answer. Is this still correct with V8 ??
Or should it be index scan ?

--
LR
Reply With Quote
  #5 (permalink)  
Old 01-17-06, 09:17
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
It is a loaded question. Your HR department is playing Russian Rullet. There are times when it will do a table scan and there are time when it will do an index scan regardless what dblevel you are running. Non technical people administering a test?
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On