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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

While, <strong>for</strong><br />

or<br />

SELECT ... FROM ... ORDER BY A DESC, B DESC<br />

SELECT ... FROM ... ORDER BY A ASC, B ASC<br />

<strong>DB2</strong> still has to per<strong>for</strong>m a sort.<br />

Table 3-10 shows a set of test cases, in which we compare queries under V7 to V8. We<br />

assume that an ascending index on EMPO has been created <strong>for</strong> table EMP. Notice that the<br />

access type in the PLAN_TABLE is I in both directions.<br />

Table 3-10 Access type and sort with backward index scan<br />

Query <strong>DB2</strong> <strong>Version</strong> Access type in<br />

PLAN_TABLE<br />

SELECT EMPNO FROM EMP<br />

ORDER BY EMPNO ASC<br />

SELECT EMPNO FROM EMP<br />

ORDER BY EMPNO DESC<br />

SELECT EMPNO FROM EMP<br />

ORDER BY EMPNO ASC<br />

SELECT EMPNO FROM EMP<br />

ORDER BY EMPNO DESC<br />

3.14 Multiple distinct<br />

Prior to <strong>DB2</strong> V8, DISTINCT cannot be used more than once in a subselect, with the exception<br />

of its use with a column function whose expression is a column. That is, it is allowed to specify<br />

multiple DISTINCT keywords as an exception on the same column like:<br />

► SELECT COUNT(DISTINCT(C1)), AVG(DISTINCT(C1))<br />

However, if you use DISTINCT keywords more than once specifying different columns, you<br />

get SQLCODE -127 which means “DISTINCT IS SPECIFIED MORE THAN ONCE IN A<br />

SUBSELECT” occurs. For instance, in V7 you cannot have the following statement:<br />

► SELECT COUNT(DISTINCT(C1)), AVG(DISTINCT(C2))<br />

With <strong>DB2</strong> V8, you can use multiple DISTINCT keywords in the SELECT statement and<br />

HAVING clause. With <strong>DB2</strong> V8, the following queries are possible:<br />

► SELECT DISTINCT COUNT(DISTINCT C1), SUM(DISTINCT C2) FROM T1<br />

► SELECT DISTINCT COUNT(DISTINCT C1), COUNT(DISTINCT C2) FROM T1 GROUP<br />

BY A3<br />

► SELECT COUNT(DISTINCT C1), AVG(DISTINCT C2) FROM T1 GROUP BY C1<br />

► SELECT COUNT(DISTINCT(A1)) FROM T1 WHERE A3 > 0 GROUP BY A2 HAVING<br />

AVG(DISTINCT (A4)) > 1<br />

In these cases in V7 you have to divide the statements into multiple SELECT statements <strong>for</strong><br />

each distinct operation of columns. From the per<strong>for</strong>mance point of view, you have to execute<br />

multiple SELECT statements to retrieve the value in multiple columns.<br />

108 <strong>DB2</strong> <strong>UDB</strong> <strong>for</strong> z/<strong>OS</strong> <strong>Version</strong> 8 Per<strong>for</strong>mance <strong>Topics</strong><br />

Notes<br />

V7 I Base case<br />

V7 I Sort needed<br />

V8 I Same as V7<br />

V8 I Sort no longer<br />

required

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

Saved successfully!

Ooh no, something went wrong!