Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b41965

Browse files
author
Neil Conway
committed
Remove some verbiage describing how min() and max() are slow when applied
to the entire table: as of current sources, they are no longer slowprovided there is an index on the column.
1 parentdd2894d commit1b41965

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.249 2005/05/23 01:29:54 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.250 2005/05/23 01:50:01 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -7317,55 +7317,16 @@ SELECT b1 = ANY((SELECT b2 FROM t2 ...)) FROM t1 ...;
73177317
<note>
73187318
<para>
73197319
Users accustomed to working with other SQL database management
7320-
systems may be surprised by the performance characteristics of
7321-
certain aggregate functions in
7322-
<productname>PostgreSQL</productname> when the aggregate is
7323-
applied to the entire table (in other words, no
7324-
<literal>WHERE</literal> clause is specified). In particular, a
7325-
query like
7320+
systems may be surprised by the performance of the
7321+
<function>count</function> aggregate when it is applied to the
7322+
entire table. A query like:
73267323
<programlisting>
7327-
SELECTmin(col) FROM sometable;
7324+
SELECTcount(*) FROM sometable;
73287325
</programlisting>
73297326
will be executed by <productname>PostgreSQL</productname> using a
7330-
sequential scan of the entire table. Other database systems may
7331-
optimize queries of this form to use an index on the column, if
7332-
one is available. Similarly, the aggregate functions
7333-
<function>max()</function> and <function>count()</function> always
7334-
require a sequential scan if applied to the entire table in
7335-
<productname>PostgreSQL</productname>.
7336-
</para>
7337-
7338-
<para>
7339-
<productname>PostgreSQL</productname> cannot easily implement this
7340-
optimization because it also allows for user-defined aggregate
7341-
queries. Since <function>min()</function>,
7342-
<function>max()</function>, and <function>count()</function> are
7343-
defined using a generic API for aggregate functions, there is no
7344-
provision for special-casing the execution of these functions
7345-
under certain circumstances.
7346-
</para>
7347-
7348-
<para>
7349-
Fortunately, there is a simple workaround for
7350-
<function>min()</function> and <function>max()</function>. The
7351-
query shown below is equivalent to the query above, except that it
7352-
can take advantage of a B-tree index if there is one present on
7353-
the column in question.
7354-
<programlisting>
7355-
SELECT col FROM sometable ORDER BY col ASC LIMIT 1;
7356-
</programlisting>
7357-
A similar query (obtained by substituting <literal>DESC</literal>
7358-
for <literal>ASC</literal> in the query above) can be used in the
7359-
place of <function>max()</function>.
7360-
</para>
7361-
7362-
<para>
7363-
Unfortunately, there is no similarly trivial workaround that can
7364-
be used to improve the performance of <function>count()</function>
7365-
when applied to the entire table.
7327+
sequential scan of the entire table.
73667328
</para>
73677329
</note>
7368-
73697330
</sect1>
73707331

73717332

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp