Author: shinz
Date: 2005-12-16 22:02:03 +0100 (Fri, 16 Dec 2005)
New Revision: 577
Log:
Loose index scans appear in 5.0 only (Domas)
Modified:
trunk/refman-4.1/optimization.xml
Modified: trunk/refman-4.1/optimization.xml
===================================================================
--- trunk/refman-4.1/optimization.xml 2005-12-16 18:46:45 UTC (rev 576)
+++ trunk/refman-4.1/optimization.xml 2005-12-16 21:02:03 UTC (rev 577)
@@ -3409,137 +3409,6 @@
performs a range scan, and then groups the resulting tuples.
</para>
- <section id="loose-index-scan">
-
- <title>&title-loose-index-scan;</title>
-
- <para>
- The most efficient way is when the index is used to directly
- retrieve the group fields. With this access method, MySQL uses
- the property of some index types (for example, B-Trees) that
- the keys are ordered. This property allows use of lookup
- groups in an index without having to consider all keys in the
- index that satisfy all <literal>WHERE</literal> conditions.
- Since this access method considers only a fraction of the keys
- in an index, it is called a <firstterm>loose index
- scan</firstterm>. When there is no <literal>WHERE</literal>
- clause, a loose index scan reads as many keys as the number of
- groups, which may be a much smaller number than that of all
- keys. If the <literal>WHERE</literal> clause contains range
- predicates (see the discussion in <xref linkend="explain"/> of
- the <literal>range</literal> join type), a loose index scan
- looks up the first key of each group that satisfies the range
- conditions, and again reads the least possible number of keys.
- This is possible under the following conditions:
- </para>
-
- <itemizedlist>
-
- <listitem>
- <para>
- The query is over a single table.
- </para>
- </listitem>
-
- <listitem>
- <para>
- The <literal>GROUP BY</literal> includes the first
- consecutive parts of the index (if instead of
- <literal>GROUP BY</literal>, the query has a
- <literal>DISTINCT</literal> clause, then all distinct
- attributes refer to the beginning of the index).
- </para>
- </listitem>
-
- <listitem>
- <para>
- The only aggregate functions used (if any) are
- <literal>MIN()</literal> and <literal>MAX()</literal>, and
- all of them refer to the same column.
- </para>
- </listitem>
-
- <listitem>
- <para>
- Any other parts of the index than those from the
- <literal>GROUP BY</literal> referenced in the query must
- be constants (that is, they must be referenced in
- equalities with constants), except for the argument of
- <literal>MIN()</literal> or <literal>MAX()</literal>
- functions.
- </para>
- </listitem>
-
- </itemizedlist>
-
- <para>
- The <literal>EXPLAIN</literal> output for such queries shows
- <literal>Using index for group-by</literal> in the
- <literal>Extra</literal> column.
- </para>
-
- <para>
- The following queries provide several examples that fall into
- this category, assuming there is an index <literal>idx(c1, c2,
- c3)</literal> on table <literal>t1(c1,c2,c3,c4)</literal>:
- </para>
-
-<programlisting>
-SELECT c1, c2 FROM t1 GROUP BY c1, c2;
-SELECT DISTINCT c1, c2 FROM t1;
-SELECT c1, MIN(c2) FROM t1 GROUP BY c1;
-SELECT c1, c2 FROM t1 WHERE c1 < <replaceable>const</replaceable> GROUP BY c1, c2;
-SELECT MAX(c3), MIN(c3), c1, c2 FROM t1 WHERE c2 > <replaceable>const</replaceable> GROUP BY c1, c2;
-SELECT c2 FROM t1 WHERE c1 < <replaceable>const</replaceable> GROUP BY c1, c2;
-SELECT c1, c2 FROM t1 WHERE c3 = <replaceable>const</replaceable> GROUP BY c1, c2;
-</programlisting>
-
- <para>
- The following queries cannot be executed with this quick
- select method, for the reasons given:
- </para>
-
- <itemizedlist>
-
- <listitem>
- <para>
- There are other aggregate functions than
- <literal>MIN()</literal> or <literal>MAX()</literal>, for
- example:
- </para>
-
-<programlisting>
-SELECT c1, SUM(c2) FROM t1 GROUP BY c1;
-</programlisting>
- </listitem>
-
- <listitem>
- <para>
- The fields in the <literal>GROUP BY</literal> clause do
- not refer to the beginning of the index, as shown here:
- </para>
-
-<programlisting>
-SELECT c1,c2 FROM t1 GROUP BY c2, c3;
-</programlisting>
- </listitem>
-
- <listitem>
- <para>
- The query refers to a part of a key that comes after the
- <literal>GROUP BY</literal> part, and for which there is
- no equality with a constant, an example being:
- </para>
-
-<programlisting>
-SELECT c1,c3 FROM t1 GROUP BY c1, c2;
-</programlisting>
- </listitem>
-
- </itemizedlist>
-
- </section>
-
<section id="tight-index-scan">
<title>&title-tight-index-scan;</title>
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r577 - trunk/refman-4.1 | stefan | 16 Dec |