281 lines
18 KiB
HTML
281 lines
18 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="SQLStatistics - Get index and statistics information for a base table" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzadphdapi.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="rzadpfnstats" />
|
|
<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>SQLStatistics</title>
|
|
</head>
|
|
<body id="rzadpfnstats"><a name="rzadpfnstats"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">SQLStatistics - Get index and statistics information for a base table</h1>
|
|
<div><div class="section"></div>
|
|
<div class="section"><h4 class="sectiontitle">Purpose</h4> <p><samp class="codeph">SQLStatistics()</samp> retrieves
|
|
index information for a given table. It also returns the cardinality and the
|
|
number of pages associated with the table and the indexes on the table. The
|
|
information is returned in a result set, which can be retrieved using the
|
|
same functions that are used to fetch a result set generated by a SELECT-statement.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Syntax</h4><pre>SQLRETURN SQLStatistics (SQLHSTMT hstmt,
|
|
SQLCHAR *szCatalogName,
|
|
SQLSMALLINT cbCatalogName,
|
|
SQLCHAR *szSchemaName,
|
|
SQLSMALLINT cbSchemaName,
|
|
SQLCHAR *szTableName,
|
|
SQLSMALLINT cbTableName,
|
|
SQLSMALLINT fUnique,
|
|
SQLSMALLINT fAccuracy);</pre>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Function arguments</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. SQLStatistics arguments</caption><thead align="left"><tr><th align="left" valign="top" width="19.776119402985074%" id="d0e48">Data type</th>
|
|
<th align="left" valign="top" width="19.776119402985074%" id="d0e50">Argument</th>
|
|
<th align="left" valign="top" width="14.925373134328357%" id="d0e52">Use</th>
|
|
<th align="left" valign="top" width="45.52238805970149%" id="d0e54">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLCHAR *</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>szCatalogName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Catalog qualifier of a three-part table name.
|
|
This must be a null pointer or a zero length string.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLCHAR *</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>szSchemaName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Schema qualifier of the specified table.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLCHAR *</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>szTableName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Table name.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLHSTMT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>hstmt</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Statement handle.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>cbCatalogName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Length of <em>cbCatalogName</em>. This must
|
|
be set to 0.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>cbSchemaName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Length of <em>szSchemaName</em>.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>cbTableName</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Length of <em>cbTableName</em>.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>fAccuracy</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Not currently used, must be set to 0.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="19.776119402985074%" headers="d0e48 ">SQLSMALLINT</td>
|
|
<td align="left" valign="top" width="19.776119402985074%" headers="d0e50 "><em>fUnique</em></td>
|
|
<td align="left" valign="top" width="14.925373134328357%" headers="d0e52 ">Input</td>
|
|
<td align="left" valign="top" width="45.52238805970149%" headers="d0e54 ">Type of index information to return: <ul><li>SQL_INDEX_UNIQUE <p>Only unique indexes are returned.</p>
|
|
</li>
|
|
<li>SQL_INDEX_ALL <p>All indexes are returned.</p>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Usage</h4><div class="p"><samp class="codeph">SQLStatistics()</samp> returns the
|
|
following types of information: <ul><li>Statistics information for the table (if available): <ul><li>When the TYPE column in the following table is set to SQL_TABLE_STAT,
|
|
the number of rows in the table and the number of pages used to store the
|
|
table.</li>
|
|
<li>When the TYPE column indicates an index, the number of unique values in
|
|
the index, and the number of pages used to store the indexes.</li>
|
|
<li>Information about each index, where each index column is represented by
|
|
one row of the result set. The result set columns are given in the following
|
|
table in the order shown; the rows in the result set are ordered by NON_UNIQUE,
|
|
TYPE, INDEX_QUALIFIER, INDEX_QUALIFIER, INDEX_NAME and ORDINAL_POSITION.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tablenoborder"><a name="rzadpfnstats__rsstats"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzadpfnstats__rsstats" width="100%" frame="hsides" border="1" rules="all"><caption>Table 2. Columns
|
|
returned by SQLStatistics</caption><thead align="left"><tr><th align="left" valign="top" width="33.33333333333333%" id="d0e192">Column name</th>
|
|
<th align="left" valign="top" width="33.33333333333333%" id="d0e194">Data type</th>
|
|
<th align="left" valign="top" width="33.33333333333333%" id="d0e196">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">TABLE_CAT</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">The name of the catalog containing TABLE_SCHEM.
|
|
This is set to NULL.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">TABLE_SCHEM</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">The name of the schema containing TABLE_NAME.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">TABLE_NAME</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128) not NULL</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Name of the table.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">NON_UNIQUE</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">SMALLINT</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Indicates whether the index prohibits duplicate
|
|
values: <ul><li>TRUE if the index allows duplicate values.</li>
|
|
<li>FALSE if the index values must be unique.</li>
|
|
<li>NULL is returned if the TYPE column indicates that this row is SQL_TABLE_STAT
|
|
(statistics information about the table itself).</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">INDEX_QUALIFIER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">The identifier used to qualify the index
|
|
name. This is NULL if the TYPE column indicates SQL_TABLE_STAT.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">INDEX_NAME</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">The name of the index. If the TYPE column
|
|
has the value SQL_TABLE_STAT, this column has the value NULL.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">TYPE</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">SMALLINT not NULL</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Indicates the type of information contained
|
|
in this row of the result set: <ul><li>SQL_TABLE_STAT <p>Indicates this row contains statistics information
|
|
on the table itself.</p>
|
|
</li>
|
|
<li>SQL_INDEX_CLUSTERED <p>Indicates this row contains information about
|
|
an index, and the index type is a clustered index.</p>
|
|
</li>
|
|
<li>SQL_INDEX_HASHED <p>Indicates this row contains information about an
|
|
index, and the index type is a hashed index.</p>
|
|
</li>
|
|
<li>SQL_INDEX_OTHER <p>Indicates this row contains information about an index,
|
|
and the index type is other than clustered or hashed.</p>
|
|
</li>
|
|
</ul>
|
|
<div class="note"><span class="notetitle">Note:</span> Currently, SQL_INDEX_OTHER is the only possible type.</div>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">ORDINAL_POSITION</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">SMALLINT</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Ordinal position of the column within the
|
|
index whose name is given in the INDEX_NAME column. A NULL value is returned
|
|
for this column if the TYPE column has the value of SQL_TABLE_STAT.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">COLUMN_NAME</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">VARCHAR(128)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Name of the column in the index.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">COLLATION</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">CHAR(1)</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 ">Sort sequence for the column; "<span class="uicontrol">A</span>"
|
|
for ascending, "<span class="uicontrol">D</span>" for descending. NULL value is returned
|
|
if the value in the TYPE column is SQL_TABLE_STAT.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">CARDINALITY</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">INTEGER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 "> <ul><li>If the TYPE column contains the value SQL_TABLE_STAT, this column contains
|
|
the number of rows in the table.</li>
|
|
<li>If the TYPE column value is not SQL_TABLE_STAT, this column contains the
|
|
number of unique values in the index.</li>
|
|
<li>A NULL value is returned if information is not available from the Database
|
|
Management System (DBMS).</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="33.33333333333333%" headers="d0e192 ">PAGES</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e194 ">INTEGER</td>
|
|
<td align="left" valign="top" width="33.33333333333333%" headers="d0e196 "> <ul><li>If the TYPE column contains the value SQL_TABLE_STAT, this column contains
|
|
the number of pages used to store the table.</li>
|
|
<li>If the TYPE column value is not SQL_TABLE_STAT, this column contains the
|
|
number of pages used to store the indexes.</li>
|
|
<li>A NULL value is returned if information is not available from the DBMS.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<p>For the row in the result set that contains table statistics
|
|
(TYPE is set to SQL_TABLE_STAT), the columns values of NON_UNIQUE, INDEX_QUALIFIER,
|
|
INDEX_NAME, ORDINAL_POSITION, COLUMN_NAME, and COLLATION are set to NULL.
|
|
If the CARDINALITY or PAGES information cannot be determined, then NULL is
|
|
returned for those columns.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Return codes</h4><ul><li>SQL_SUCCESS</li>
|
|
<li>SQL_SUCCESS_WITH_INFO</li>
|
|
<li>SQL_ERROR</li>
|
|
<li>SQL_INVALID_HANDLE</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Diagnostics</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="rows"><caption>Table 3. SQLStatistics SQLSTATEs</caption><thead align="left"><tr><th align="left" valign="top" width="25%" id="d0e358">SQLSTATE</th>
|
|
<th align="left" valign="top" width="25%" id="d0e360">Description</th>
|
|
<th align="left" valign="top" width="50%" id="d0e362">Explanation</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td align="left" valign="top" width="25%" headers="d0e358 "><strong>240</strong>00</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e360 ">Cursor state that is not valid</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e362 ">Cursor related information is requested,
|
|
but no cursor is open.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e358 "><strong>40</strong>003 <strong>*</strong></td>
|
|
<td align="left" valign="top" width="25%" headers="d0e360 ">Statement completion unknown</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e362 ">The communication link between the CLI and
|
|
the data source fails before the function completes processing.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e358 "><strong>HY</strong>001</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e360 ">Memory allocation failure</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e362 ">The driver is unable to allocate memory required
|
|
to support the processing or completion of the function.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e358 "><strong>HY</strong>009</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e360 ">Argument or buffer length that is not valid</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e362 ">The value of one of the name length arguments
|
|
is less than 0, but not equal to SQL_NTS.</td>
|
|
</tr>
|
|
<tr><td valign="top" width="25%" headers="d0e358 "><strong>HY</strong>021</td>
|
|
<td valign="top" width="25%" headers="d0e360 ">Internal descriptor that is not valid </td>
|
|
<td valign="top" width="50%" headers="d0e362 ">The internal descriptor cannot be addressed or allocated,
|
|
or it contains a value that is not valid.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="25%" headers="d0e358 "><strong>HY</strong>C00</td>
|
|
<td align="left" valign="top" width="25%" headers="d0e360 ">Driver not capable</td>
|
|
<td align="left" valign="top" width="50%" headers="d0e362 ">The catalog part (the first part) of a three-part
|
|
table name is not supported by the data source.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzadphdapi.htm" title="This topic provides a description of each CLI function.">DB2 UDB CLI functions</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |