MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regarding Index scan

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
basheerbaba
Beginner


Joined: 03 Jan 2007
Posts: 13
Topics: 6
Location: Hyderabad,India

PostPosted: Mon Feb 18, 2008 4:36 am    Post subject: Regarding Index scan Reply with quote

Hi ,

I have two tables called table1, table2.

In both tables I have indexed columns and as well as non indexed columns.

in the select statement

if I give some index and non-index columns from table 1 and table2 then table 1 is getting Index scan ; table2 is getting table scan.

My doubt is why table2 only is getting table scan?

I think so I am clear with my doubt.

Please let me know any thing not clear.

Thanks for help in advance.

Basheer.
Back to top
View user's profile Send private message Yahoo Messenger
acevedo
Beginner


Joined: 03 Dec 2002
Posts: 127
Topics: 0
Location: Europe

PostPosted: Mon Feb 18, 2008 5:54 am    Post subject: Reply with quote

you should post your INDEX declarations and your WHERE...
what about the FIELDs definitions? are the Working Storage fields definitions EXACTLY as those declared in the DB2 Table? what about Statistics?
Back to top
View user's profile Send private message
basheerbaba
Beginner


Joined: 03 Jan 2007
Posts: 13
Topics: 6
Location: Hyderabad,India

PostPosted: Mon Feb 18, 2008 8:22 am    Post subject: Reply with quote

Hi acevedo

Thanks for replay!!!!!!!

Please find the declarations of tables and indexes and as well as query

Table1 declaration:
Code:

   EXEC SQL DECLARE Table1 TABLE                         
     ( col1                       CHAR(10) NOT NULL,                   
       col2                       CHAR(50) NOT NULL,         
       col3                       TIMESTAMP NOT NULL         
     ) END-EXEC.         



Table2 declaration:

     EXEC SQL DECLARE TABLE2 TABLE                     
     ( col1                   CHAR(10) NOT NULL,         
       col2                   CHAR(6) NOT NULL,           
       col3                   CHAR(6) NOT NULL,           
       col4                   CHAR(1) NOT NULL,           
       col5                   CHAR(4) NOT NULL,           
       col6                   CHAR(8 ) NOT NULL,           
       col7                   CHAR(6) NOT NULL,           
       col8                   DECIMAL(4, 0) NOT NULL,     
       col9                   CHAR(1) NOT NULL,           
       col10                  CHAR(50) NOT NULL,         
       col11                  CHAR(65) NOT NULL,         
       col12                  CHAR(56) NOT NULL,         
       col13                  CHAR(3) NOT NULL,           
       col14                        TIMESTAMP NOT NULL         
     ) END-EXEC.                                           


In Table1 Col1 indexed by Index1
          Col2 indexed by Index2
          Col3 indexed by Index3
          Col6 indexed by Index6
          Col7 indexed by Index7
          Col8 indexed by Index8
 
In Table2 Col2 indexed by Indexa

         

SELECT  T1.col1,                                             
        T2.col6,                               
        T2.col7,                               
        T2.col3,                           
        T2.col1,                           
        T2.col8,                             
        T2.col4 ,              ------------------------->   Non-indexed column
        T1.col1,               ------------------------->   Non-indexed column
                               
   FROM  Table2 T2, Table1 T1
   WHERE   T2.col1      =  T1.col1     
    AND  ( T2.col1     >= ?                   
    AND    T2.col1     <= ?             )     
    AND  ( T2.col2  >= ?                   
    AND    T2.col2  <= ?             )     
    AND  ( T2.col3 >= ?                   
AND    T2.col3 <= ?             )       
AND                                                 
(     T2.col1    >  ?                       
 OR ( T2.col1    >= ?                     AND
      T2.col2 >  ?                     ) 
 OR ( T2.col1    >= ?                     AND
      T2.col2 >= ?                     AND
     T2.col3 >  ?                      )
 OR ( T2.col1    >= ?                     AND
      T2.col2 >= ?                     AND
    T2.col3 >=  ?                     AND
      T2.col6    >  ?                   )   
 OR ( T2.col1    >= ?                     AND
      T2.col2 >= ?                     AND
    T2.col3 >=  ?                     AND
      T2.col6    >= ?                     AND
      T2.col7    >  ?                   )   
 OR ( T2.col1    >= ?                     AND
      T2.col2 >= ?                     AND
    T2.col3 >=  ?                     AND
      T2.col6    >= ?                     AND
      T2.col7    >= ?                     AND
      T2.col8   >  ?                   )   
)                                                   
 ORDER BY T2.col1     ASC,   
          T2.col2           ASC,   
          T2.col3           ASC,   
          T2.col6           ASC,   
          T2.col7          ASC,   
          T2.col8          ASC   
FOR FETCH ONLY WITH UR
Back to top
View user's profile Send private message Yahoo Messenger
basheerbaba
Beginner


Joined: 03 Jan 2007
Posts: 13
Topics: 6
Location: Hyderabad,India

PostPosted: Mon Feb 18, 2008 8:22 am    Post subject: Reply with quote

Hi acevedo

Thanks for replay!!!!!!!

Please find the declarations of tables and indexes and as well as query

Table1 declaration:

EXEC SQL DECLARE Table1 TABLE
( col1 CHAR(10) NOT NULL,
col2 CHAR(50) NOT NULL,
col3 TIMESTAMP NOT NULL
) END-EXEC.



Table2 declaration:

EXEC SQL DECLARE TABLE2 TABLE
( col1 CHAR(10) NOT NULL,
col2 CHAR(6) NOT NULL,
col3 CHAR(6) NOT NULL,
col4 CHAR(1) NOT NULL,
col5 CHAR(4) NOT NULL,
col6 CHAR(8 ) NOT NULL,
col7 CHAR(6) NOT NULL,
col8 DECIMAL(4, 0) NOT NULL,
col9 CHAR(1) NOT NULL,
col10 CHAR(50) NOT NULL,
col11 CHAR(65) NOT NULL,
col12 CHAR(56) NOT NULL,
col13 CHAR(3) NOT NULL,
col14 TIMESTAMP NOT NULL
) END-EXEC.


In Table1 Col1 indexed by Index1
Col2 indexed by Index2
Col3 indexed by Index3
Col6 indexed by Index6
Col7 indexed by Index7
Col8 indexed by Index8

In Table2 Col2 indexed by Indexa



SELECT T1.col1,
T2.col6,
T2.col7,
T2.col3,
T2.col1,
T2.col8,
T2.col4 , -------------------------> Non-indexed column
T1.col1, -------------------------> Non-indexed column

FROM Table2 T2, Table1 T1
WHERE T2.col1 = T1.col1
AND ( T2.col1 >= ?
AND T2.col1 <= ? )
AND ( T2.col2 >= ?
AND T2.col2 <= ? )
AND ( T2.col3 >= ?
AND T2.col3 <= ? )
AND
( T2.col1 > ?
OR ( T2.col1 >= ? AND
T2.col2 > ? )
OR ( T2.col1 >= ? AND
T2.col2 >= ? AND
T2.col3 > ? )
OR ( T2.col1 >= ? AND
T2.col2 >= ? AND
T2.col3 >= ? AND
T2.col6 > ? )
OR ( T2.col1 >= ? AND
T2.col2 >= ? AND
T2.col3 >= ? AND
T2.col6 >= ? AND
T2.col7 > ? )
OR ( T2.col1 >= ? AND
T2.col2 >= ? AND
T2.col3 >= ? AND
T2.col6 >= ? AND
T2.col7 >= ? AND
T2.col8 > ? )
)
ORDER BY T2.col1 ASC,
T2.col2 ASC,
T2.col3 ASC,
T2.col6 ASC,
T2.col7 ASC,
T2.col8 ASC
FOR FETCH ONLY WITH UR
Back to top
View user's profile Send private message Yahoo Messenger
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Tue Feb 19, 2008 8:12 pm    Post subject: Reply with quote

1. the select columns have no impact on index scan unless you want to index scan only.
2. focus on your where clause
Code:
         T2.col1      =  T1.col1     

only index on T1.col1 needed for table T1 in this query
Code:
AND  ( T2.col1     >= ?  AND    T2.col1     <= ?      )   

if there is index on T2.col1, the index may be used
same on col2, col3
but you have no index on col1 or col2 or col3
even you have the index, whethere it will be used, depend on how many rows returen by each filter.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group