Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
The use of ?BEWTEEN? and <= and >= is usually a wash in performance. However, there is one condition where it is not a wash.
If, for conversation, we say that you have a table where part of the KEY is EFF_DATE and EXPIRE_DATE. And you are looking for rows that are currently active. The are two ways to select them.
SELECT *
FROM TABLE
WHERE EFF_DATE <= :CURRENT-DATE
AND EXPIRE_DATE >= :CURRENT-DATE
Or
SELECT *
FROM TABLE
WHERE :CURRENT-DATE BETWEEN EFF_DATE AND EXPIRE_DATE
In the first case DB2 will use the index to select the rows, good performance,
But in the second case, DB2 cannot use the indexes to select the rows, and must read every row in the table to select the rows. This really becomes an issue if you also add to the SQL
?AND ACCOUNT_TYPE = :WS-ACCOUNT-TYPE? and you have to read the entire table for each account type you want to process.