113 lines
7.0 KiB
HTML
113 lines
7.0 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="View materialization implementation" />
|
|
<meta name="abstract" content="The view materialization implementation runs the query of the view and places the results in a temporary result. The view reference in the user's query is then replaced with the temporary, and the query is run against the temporary result." />
|
|
<meta name="description" content="The view materialization implementation runs the query of the view and places the results in a temporary result. The view reference in the user's query is then replaced with the temporary, and the query is run against the temporary result." />
|
|
<meta name="DC.Relation" scheme="URI" content="viewopt.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="viewmaterialize" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>View materialization implementation</title>
|
|
</head>
|
|
<body id="viewmaterialize"><a name="viewmaterialize"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">View materialization implementation</h1>
|
|
<div><p>The view materialization implementation runs the query of the view
|
|
and places the results in a temporary result. The view reference in the user's
|
|
query is then replaced with the temporary, and the query is run against the
|
|
temporary result.</p>
|
|
<div class="section"><p><img src="./delta.gif" alt="Start of change" />View materialization is done whenever it is not possible
|
|
to create a view composite. Note that for SQE, view materialization is optional.
|
|
The following types of queries require view materialization:<img src="./deltaend.gif" alt="End of change" /></p>
|
|
<img src="./delta.gif" alt="Start of change" /><ul><li>The outermost select of the view contains grouping, the query contains
|
|
grouping, and refers to a column derived from a column function in the view
|
|
in the HAVING or select-list.</li>
|
|
<li>The query is a join and the outermost select of the view contains grouping
|
|
or DISTINCT.</li>
|
|
<li>The outermost select of the view contains DISTINCT, and the query has
|
|
UNION, grouping, or DISTINCT and one of the following: <ul><li>Only the query has a shared weight NLSS table</li>
|
|
<li>Only the view has a shared weight NLSS table</li>
|
|
<li>Both the query and the view have a shared weight NLSS table, but the tables
|
|
are different.</li>
|
|
</ul>
|
|
</li>
|
|
<li>The query contains a column function and the outermost select of the view
|
|
contains a DISTINCT</li>
|
|
<li>The view does not contain an access plan. This can occur when a view references
|
|
a view and a view composite cannot be created because of one of the reasons
|
|
listed above. This does not apply to nested table expressions and common table
|
|
expressions.</li>
|
|
<li>The Common table expression (CTE) is reference more than once in the query's
|
|
FROM clause(s) and the CTE's SELECT clause references a MODIFIES or EXTERNAL
|
|
ACTION UDF.</li>
|
|
</ul><img src="./deltaend.gif" alt="End of change" />
|
|
<p>When a temporary result table is created, access methods that are
|
|
allowed with ALWCPYDTA(*OPTIMIZE) may be used to implement the query. These
|
|
methods include hash grouping, hash join, and bitmaps.</p>
|
|
</div>
|
|
<div class="section"><p>See the following examples:</p>
|
|
<pre><strong>CREATE VIEW</strong> AVGSALVW <strong>AS</strong>
|
|
<strong>SELECT</strong> WORKDEPT, AVG(SALARY) <strong>AS</strong> AVGSAL
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE
|
|
<strong>GROUP BY</strong> WORKDEPT</pre>
|
|
</div>
|
|
<div class="section"><p>SQL example: </p>
|
|
<pre> <strong>SELECT</strong> D.DEPTNAME, A.AVGSAL
|
|
<strong>FROM</strong> CORPDATA.DEPARTMENT D, AVGSALVW A
|
|
<strong>WHERE</strong> D.DEPTNO=A.WORKDEPT</pre>
|
|
</div>
|
|
<div class="section"><p>In this case, a view composite cannot be created since a join
|
|
query references a grouping view. The results of AVGSALVW are placed in a
|
|
temporary result table (*QUERY0001). The view reference AVGSALVW is replaced
|
|
with the temporary result table. The new query is then run. The generated
|
|
query looks like the following: </p>
|
|
<pre><strong>SELECT</strong> D.DEPTNAME, A.AVGSAL
|
|
<strong>FROM</strong> CORPDATA.DEPARTMENT D, *QUERY0001 A
|
|
<strong>WHERE</strong> D.DEPTNO=A.WORKDEPT</pre>
|
|
<div class="note"><span class="notetitle">Note:</span> The new query that the
|
|
query optimizer generates is not visible to users. Only the original query
|
|
against the view will be seen by users and database performance tools.</div>
|
|
</div>
|
|
<div class="section"><p>Whenever possible, isolatable selection from the query, except
|
|
subquery predicates, is added to the view materialization process. This results
|
|
in smaller temporary result tables and allows existing indexes to be used
|
|
when materializing the view. This will not be done if there is more than
|
|
one reference to the same view or common table expression in the query. The
|
|
following is an example where isolatable selection is added to the view materialization: </p>
|
|
<pre><strong>SELECT</strong> D.DEPTNAME,A.AVGSAL
|
|
<strong>FROM</strong> CORPDATA.DEPARTMENT D, AVGSALVW A
|
|
<strong>WHERE</strong> D.DEPTNO=A.WORKDEPT <strong>AND</strong>
|
|
A.WORKDEPT <strong>LIKE</strong> 'D%' <strong>AND</strong> AVGSAL>10000</pre>
|
|
</div>
|
|
<div class="section"><p>The isolatable selection from the query is added to the view resulting
|
|
in a new query to generate the temporary result table: </p>
|
|
<pre><strong>SELECT</strong> WORKDEPT, AVG(SALARY) <strong>AS</strong> AVGSAL
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE
|
|
<strong>WHERE</strong> WORKDEPT <strong>LIKE</strong> 'D%'
|
|
<strong>GROUP BY</strong> WORKDEPT
|
|
<strong>HAVING AVG</strong>(SALARY)>10000 </pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="viewopt.htm" title="Views, derived tables (nested table expressions or NTEs), and common table expressions (CTEs) are implemented by the query optimizer using one of two methods.">View implementation</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |