86 lines
5.0 KiB
HTML
86 lines
5.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="concept" />
|
|
<meta name="DC.Title" content="Instances where an index is not used" />
|
|
<meta name="abstract" content="DB2 Universal Database for iSeries does not use indexes in the following instances:" />
|
|
<meta name="description" content="DB2 Universal Database for iSeries does not use indexes in the following instances:" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzajqindexopt.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="avoidinstance" />
|
|
<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>Instances where an index is not used</title>
|
|
</head>
|
|
<body id="avoidinstance"><a name="avoidinstance"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Instances where an index is not used</h1>
|
|
<div><p><span class="keyword">DB2 Universal Database™ for iSeries™</span> does
|
|
not use indexes in the following instances:</p>
|
|
<ul><li>For a column that is expected to be updated; for example, when using SQL,
|
|
your program might include the following: <pre>EXEC SQL
|
|
<strong>DECLARE</strong> DEPTEMP <strong>CURSOR FOR
|
|
SELECT</strong> EMPNO, LASTNAME, WORKDEPT
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE
|
|
<strong>WHERE</strong> (WORKDEPT = 'D11' <strong>OR</strong>
|
|
WORKDEPT = 'D21') <strong>AND</strong>
|
|
EMPNO = '000190'
|
|
<strong>FOR UPDATE OF</strong> EMPNO, WORKDEPT
|
|
END-EXEC.</pre>
|
|
<p>When using the <span class="cmdname">OPNQRYF</span> command,
|
|
for example: </p>
|
|
<pre>OPNQRYF FILE((CORPDATA/EMPLOYEE)) OPTION(*ALL)
|
|
QRYSLT('(WORKDEPT *EQ ''D11'' *OR WORKDEPT *EQ ''D21'')
|
|
*AND EMPNO *EQ ''000190''')</pre>
|
|
<p>Even if you do not intend to
|
|
update the employee's department, the system cannot use an index with a key
|
|
of WORKDEPT.</p>
|
|
<p>The system can use an index if all of the updateable columns
|
|
used within the index are also used within the query as an isolatable selection
|
|
predicate with an equal operator. In the previous example, the system uses
|
|
an index with a key of EMPNO.</p>
|
|
<p>The system can operate more efficiently
|
|
if the FOR UPDATE OF column list only names the column you intend to update:
|
|
<em>WORKDEPT</em>. Therefore, do not specify a column in the FOR UPDATE OF
|
|
column list unless you intend to update the column.</p>
|
|
<p>If you have an updateable
|
|
cursor because of dynamic SQL or the FOR UPDATE clause was not specified and
|
|
the program contains an UPDATE statement then all columns can be updated.</p>
|
|
</li>
|
|
<li>For a column being compared with another column from the same row. For
|
|
example, when using SQL, your program might include the following: <pre>EXEC SQL
|
|
<strong>DECLARE</strong> DEPTDATA <strong>CURSOR FOR
|
|
SELECT</strong> WORKDEPT, DEPTNAME
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE
|
|
<strong>WHERE</strong> WORKDEPT = ADMRDEPT
|
|
END-EXEC.</pre>
|
|
<p>When using the OPNQRYF command, for example: </p>
|
|
<pre>OPNQRYF FILE (EMPLOYEE) FORMAT(FORMAT1)
|
|
QRYSLT('WORKDEPT *EQ ADMRDEPT')</pre>
|
|
<p>Even though there is an index
|
|
for <em>WORKDEPT</em> and another index for <em>ADMRDEPT</em>, <span class="keyword">DB2 Universal Database for iSeries</span> will
|
|
not use either index. The index has no added benefit because every row of
|
|
the table needs to be looked at.</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajqindexopt.htm" title="Since the iSeries optimizer uses cost based optimization, the more information that the optimizer is given about the rows and columns in the database, the better able the optimizer is to create the best possible (least costly/fastest) access plan for the query. With the information from the indexes, the optimizer can make better choices about how to process the request (local selection, joins, grouping, and ordering).">Indexes and the optimizer</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |