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.

3.2.1 Creating MQTs<br />

MQTs compared to views<br />

► MQTs occupy storage space<br />

► MQTs are not usually referenced in a user query, but typically referenced via query rewrite<br />

by <strong>DB2</strong>.<br />

MQTs compared to indexes<br />

► MQTs can be associated with multiple tables. An index can be created <strong>for</strong> one table only.<br />

► Exploitation of MQTs and indexes is transparent to the applications.<br />

We use the extended CREATE TABLE SQL statement to define an MQT and we:<br />

► Specify a fullselect associated with a table<br />

► Specify the mechanisms that are used to refresh the MQT<br />

► Enable/disable an MQT <strong>for</strong> automatic query rewrite<br />

The privilege set needed to define the MQT must include at least one of the following:<br />

► The CREATETAB privilege <strong>for</strong> the database, implicitly or explicitly specified by the IN<br />

clause<br />

► DBADM, DBCTRL, or DBMAINT authority <strong>for</strong> the database in which the table is being<br />

created<br />

► SYSADM or SYSCTRL authority<br />

See Example 3-3 <strong>for</strong> the DDL of a materialized query table.<br />

Example 3-3 Define a table as MQT<br />

CREATE TABLE TRANSCNT (ACCTID, LOCID, YEAR, CNT) AS (<br />

SELECT ACCTID, LOCID, YEAR, COUNT(*)<br />

FROM TRANS<br />

GROUP BY ACCTID, LOCID, YEAR )<br />

DATA INITIALLY DEFERRED<br />

REFRESH DEFERRED<br />

MAINTAINED BY SYSTEM<br />

ENABLE QUERY OPTIMIZATION;<br />

Options creating MQTs<br />

The options are:<br />

► DATA INITIALLY DEFERRED<br />

– The MQTs are not populated at creation<br />

– Use REFRESH TABLE to populate a system-maintained MQT<br />

– Use the INSERT statement to insert data into a user-maintained MQT or use LOAD<br />

► REFRESH DEFERRED<br />

– Data in the MQT is not refreshed when its base tables are updated<br />

– Can be refreshed any time using the REFRESH TABLE statement<br />

► MAINTAINED BY SYSTEM/USER<br />

► ENABLE /DISABLE QUERY OPTIMIZATION<br />

Referential constraints between base tables are also an important factor in determining<br />

whether a materialized query table can be used <strong>for</strong> a query.<br />

40 <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>

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

Saved successfully!

Ooh no, something went wrong!