19.06.2013 Views

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

DB2 UDB for z/OS Version 8 Performance Topics - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.4.4 Conclusions<br />

Summary of measurements with a predicate comparing a string data type with different<br />

lengths:<br />

► Elapsed time in V7 = 10.65 sec. and in V8 = 1.11 sec. (reduction of 89%)<br />

► CPU time in V7 = 3.24 sec. and in V8 = 0.08 sec. (reduction of 97%)<br />

► Predicates comparing mismatched string data types are stage 1 and indexable with minor<br />

exceptions.<br />

► Predicates comparing mismatched numeric data types are stage 1 and indexable with<br />

minor exceptions.<br />

3.4.5 Recommendations<br />

► Consider rebinding plans or packages to get better access paths.<br />

► Consider creating an index <strong>for</strong> the mismatched columns to enable index access.<br />

3.4.6 Considerations on CASTing<br />

In <strong>DB2</strong> V7, we recommend you use the CAST function to make both data types the same.<br />

However, if you do this, first you add some overhead, and then you generally dictate the join<br />

sequence because <strong>DB2</strong> favors the index and picks the simple column side as inner table. Let<br />

us look at the following SELECT:<br />

SELECT *<br />

FROM CUST AS C, ORD_DEC AS O<br />

WHERE C.CUST_NO = O.CUST_NO;<br />

If you rewrite the predicate as ‘.CUST_NO = CAST(O.CUST_NO AS INTEGER)’, <strong>DB2</strong> very<br />

likely picks the CUST table as inner table. Furthermore, since ORD_DEC.CUST_NO is<br />

DEC(15,0), this has a bigger range than the INTEGER type. Unless you are very sure that all<br />

the values in the ORD_DEC.CUST_NO are within the range of INTEGER, the CAST may fail<br />

and <strong>DB2</strong> may return an error. In <strong>DB2</strong> V8, unless you really want to dictate the join sequence,<br />

it is better not to add any CAST and let <strong>DB2</strong> choose the join sequence based on costing.<br />

Generally this provides better per<strong>for</strong>mance.<br />

3.5 Multi-predicate access path enhancement<br />

Queries which contain two or more predicates referencing a table can get a better access<br />

path with statistics <strong>for</strong> a group of columns (non-indexed or non-leading index columns)<br />

collected by RUNSTATS in V8.<br />

Long running queries with skewed data distribution or column correlation type environment<br />

involving joins with multiple predicates on columns that are not the leading columns of an<br />

index or columns that do not participate in indexes are good candidates to benefit from<br />

improved access paths.<br />

The new access path in V8 can change the sequence of tables participating in joins involving<br />

multiple tables to take advantage of early filtering, and as a result, accessing fewer pages to<br />

execute the SQL statement.<br />

Chapter 3. SQL per<strong>for</strong>mance 71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!