I’ve just seen one of the most shockingly stupid pieces of SQL in 20 years of DB2 Administration:

SELECT   (CURRENT DATE – :H MONTHS)
INTO     :H                        
FROM     TABLE1

It does a non-matching index scan of a table of 342,038,069 rows, performing 16,248 getpages at a cost of 1,426,790 timerons, when all it wants is the current date minus x months! They haven’t heard of SYSIBM.SYSDUMMY1, obviously.

Advertisements