1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-->
<refentry id="fn_key_estimate">
<refmeta>
<refentrytitle>key_estimate</refentrytitle>
<refmiscinfo>admin</refmiscinfo>
<refmiscinfo>statistics</refmiscinfo>
<refmiscinfo>stat</refmiscinfo>
</refmeta>
<refnamediv>
<refname>key_estimate</refname>
<refpurpose>Get an estimate of row count for a given set of leading index key parts</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_key_estimate">
<funcprototype id="fproto_key_estimate">
<funcdef><function>key_estimate</function></funcdef>
<paramdef>in <parameter>table_name</parameter> varchar</paramdef>
<paramdef>in <parameter>index_name</parameter> varchar</paramdef>
<paramdef>in <parameter>k1</parameter> any</paramdef>
<paramdef><parameter>...</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="desc_key_estimate"><title>Description</title>
<para>Given a table and an index, this function takes a random sample of the index,
with the first key part equal to the third argument, the second equal to the fourth argument and so on.
If only the table and index are given, the returned value is the approximate count of the entire index.
</para>
<para>Normal cast rules are applied to convert the arguments to the types of the corresponding key parts.
If the cast fails, -1 is returned.
</para>
<para>The estimates are typically within 10% of the real count. If there have been random
deletions or inserts leading to uneven page filling or if index entries are of greatly varying $
length, the estimates may be less precise.
</para>
</refsect1>
<refsect1 id="params_key_estimate">
<title>Parameters</title>
<refsect2><title>table_name</title>
<para>The name of the table as appears in SYS_KEYS, case sensitive.</para>
</refsect2>
<refsect2><title>index_name</title>
<para>The name of the index as appears in sys_keys, case sensitive.</para>
</refsect2>
<refsect2><title>k1</title>
<para>The value of the first key part. Any number of arguments, up to the number
of key parts in the index in question may follow.</para>
</refsect2>
</refsect1>
<refsect1 id="ret_key_estimate"><title>Return</title>
<para>Key_estimate returns the approximate count of entries in the index with the
specified values in the leading key parts. -1 if cannot be determined.</para>
</refsect1>
<refsect1 id="examples_key_estimate">
<title>Example</title>
<example id="ex_key_estimate">
<title>Returns the approximate count of entries in index STR1 where the first key part is
the string '123'.</title>
<programlisting><![CDATA[
select key_estimate ('DB.DBA.T1', 'STR1', '123');
]]></programlisting>
</example>
</refsect1>
</refentry>
|