|
1 | 1 | <!-- |
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 $ |
3 | 3 | PostgreSQL documentation |
4 | 4 | --> |
5 | 5 |
|
@@ -7317,55 +7317,16 @@ SELECT b1 = ANY((SELECT b2 FROM t2 ...)) FROM t1 ...; |
7317 | 7317 | <note> |
7318 | 7318 | <para> |
7319 | 7319 | 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: |
7326 | 7323 | <programlisting> |
7327 | | -SELECT min(col) FROM sometable; |
| 7324 | +SELECT count(*) FROM sometable; |
7328 | 7325 | </programlisting> |
7329 | 7326 | 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. |
7366 | 7328 | </para> |
7367 | 7329 | </note> |
7368 | | - |
7369 | 7330 | </sect1> |
7370 | 7331 |
|
7371 | 7332 |
|
|
0 commit comments