Joined: 03 Dec 2002 Posts: 127 Topics: 0 Location: Europe
Posted: Mon Feb 18, 2008 5:54 am Post subject:
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?
Joined: 03 Jan 2007 Posts: 13 Topics: 6 Location: Hyderabad,India
Posted: Mon Feb 18, 2008 8:22 am Post subject:
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
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
Joined: 03 Jan 2007 Posts: 13 Topics: 6 Location: Hyderabad,India
Posted: Mon Feb 18, 2008 8:22 am Post subject:
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
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
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.
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