Learnings

Monday, March 23, 2009

Some query tuning tips for DB2

Some tips to influence the DB2 optimizer:
1. To avoid using an index, add an OR 0=1 predicate. E.g, Select * From T1 where (C1=:V OR 0=1). The same trick can indirectly be used to modify the join order also (if indexes determine the initial join order)
2. Use OPTIMIZE for 1 ROWS to avoid sorts. There is also a CLI variable called OPTIMIZEFORNROWS that will cause this clause to be appended to all queries.
3. OPTIMIZE FOR 1 ROWS also turns off both list and sequential prefetching as we are telling DB2 that we are only interested in the first row

Monday, March 16, 2009

Collecting statistics for whole database (DB2)

REORGCHK UPDATE STATISTICS ON TABLE ALL
will end up collecting statistics on all tables.

or
REORGCHK UPDATE STATISTICS ON SCHEME DB2ADMIN
will do so for the said schema.

Statistics will be collected at the level of default RUNSTATS options.
Applies to DB2 LUW only. Here is the devworks article:
http://www.ibm.com/developerworks/data/library/techarticle/dm-0412pay/

Labels: