99 lines
5.9 KiB
HTML
99 lines
5.9 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="Index grouping implementation" />
|
|
<meta name="abstract" content="There are two primary ways to implement grouping via an index: Ordered grouping and pre-summarized processing." />
|
|
<meta name="description" content="There are two primary ways to implement grouping via an index: Ordered grouping and pre-summarized processing." />
|
|
<meta name="DC.Relation" scheme="URI" content="groupopt.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="idxgrpingimp" />
|
|
<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>Index grouping implementation</title>
|
|
</head>
|
|
<body id="idxgrpingimp"><a name="idxgrpingimp"><!-- --></a>
|
|
<img src="./delta.gif" alt="Start of change" /><!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Index grouping implementation</h1>
|
|
<div><p>There are two primary ways to implement grouping via an index:
|
|
Ordered grouping and pre-summarized processing.</p>
|
|
<div class="section"><h4 class="sectiontitle">Ordered grouping</h4><p>This implementation utilizes the
|
|
Radix Index Scan or the Radix Index Probe access methods to perform the grouping.
|
|
An index is required that contains all of the grouping columns as contiguous
|
|
leftmost key columns. The database manager accesses the individual groups
|
|
through the index and performs the requested summary functions.</p>
|
|
<p>Since
|
|
the index, by definition, already has all of the key values grouped together,
|
|
the first group result can be returned in less time than the hashing method.
|
|
This is because of the temporary result that is required for the hashing method.
|
|
This implementation can be beneficial if an application does not need to retrieve
|
|
all of the group results or if an index already exists that matches the grouping
|
|
columns.</p>
|
|
<p>When the grouping is implemented with an index and a permanent
|
|
index does not already exist that satisfies grouping columns, a temporary
|
|
index is created. The grouping columns specified within the query are used
|
|
as the key columns for this index.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Pre-summarized processing</h4><p>This SQE only implementation
|
|
utilizes an Encoded Vector Index to extract the summary information already
|
|
in the index's symbol table. The symbol table portion of an EVI contains the
|
|
unique values of the key along with a count of the number of table records
|
|
that have that unique value, basically the grouping for the columns of the
|
|
index key are already performed. If the query references a single table and
|
|
performs simple aggregation, the EVI may be used for quick access to the grouping
|
|
results. For example, consider the following query:</p>
|
|
<pre><strong>SELECT COUNT</strong>(*), col1
|
|
<strong>FROM</strong> t1
|
|
<strong>GROUP BY</strong> col1</pre>
|
|
<p>If an EVI exists over t1 with a key of
|
|
col1, the optimizer can rewrite the query to access the precomputed grouping
|
|
answer in the EVI symbol table. This can result in dramatic improvements in
|
|
queries when the number of records in the table is large and the number of
|
|
resulting groups is small (relative to the size of the table). This method
|
|
is also possible with selection (WHERE clause), as long as the reference columns
|
|
are in the key definition of the EVI. For example, consider the following
|
|
query:</p>
|
|
<pre><strong>SELECT COUNT</strong>(*), col1
|
|
<strong>FROM</strong> t1
|
|
<strong>WHERE</strong> col1 > 100
|
|
<strong>GROUP BY</strong> col1</pre>
|
|
<p>This query can be rewritten by the optimizer to make use of
|
|
the EVI. This pre-summarized processing works for DISTINCT processing, GROUP
|
|
BY and for column function COUNT. All columns of the table referenced in the
|
|
query must also be in the key definition of the EVI. So, for example, the
|
|
following query can be made to use the EVI:</p>
|
|
<pre><strong>SELECT DISTINCT</strong> col1
|
|
<strong>FROM</strong> t1</pre>
|
|
<p>However, this query cannot:</p>
|
|
<pre><strong>SELECT DISTINCT</strong> col1
|
|
<strong>FROM</strong> t1
|
|
<strong>WHERE</strong> col2 > 1</pre>
|
|
<p>The reason that this query cannot use the EVI is because it
|
|
references col2 of the table, which is not in the key definition of the EVI.
|
|
Note also that if multiple columns are defined in the EVI key, for example,
|
|
col1 and col2, that it is important that the left most columns of the key
|
|
be utilized. For example, if an EVI existed with a key definition of (col1,
|
|
col2), but the query referenced just col2, it is very unlikely the EVI will
|
|
be used.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="groupopt.htm" title="DB2 Universal Database for iSeries has certain techniques to use when the optimizer encounters grouping. The query optimizer chooses its methods for optimizing your query.">Grouping optimization</a></div>
|
|
</div>
|
|
</div>
|
|
<img src="./deltaend.gif" alt="End of change" /></body>
|
|
</html> |