diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-12 04:26:34 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-12 04:26:34 +0000 |
commit | 2e7a68896bfa84b28cd57e23e141aa9c899275c7 (patch) | |
tree | 11d360de8f7aab0d5c3345a45e61169c40f83538 /doc/src/sgml/ref/create_aggregate.sgml | |
parent | 3803f243790466722cb6cd26118f48629261cb58 (diff) |
Add aggsortop column to pg_aggregate, so that MIN/MAX optimization can
be supported for all datatypes. Add CREATE AGGREGATE and pg_dump support
too. Add specialized min/max aggregates for bpchar, instead of depending
on text's min/max, because otherwise the possible use of bpchar indexes
cannot be recognized.
initdb forced because of catalog changes.
Diffstat (limited to 'doc/src/sgml/ref/create_aggregate.sgml')
-rw-r--r-- | doc/src/sgml/ref/create_aggregate.sgml | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/doc/src/sgml/ref/create_aggregate.sgml b/doc/src/sgml/ref/create_aggregate.sgml index 4ae1d1dd8cd..24e233f5894 100644 --- a/doc/src/sgml/ref/create_aggregate.sgml +++ b/doc/src/sgml/ref/create_aggregate.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/create_aggregate.sgml,v 1.31 2005/01/04 00:39:53 tgl Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/create_aggregate.sgml,v 1.32 2005/04/12 04:26:15 tgl Exp $ PostgreSQL documentation --> @@ -26,6 +26,7 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> ( STYPE = <replaceable class="PARAMETER">state_data_type</replaceable> [ , FINALFUNC = <replaceable class="PARAMETER">ffunc</replaceable> ] [ , INITCOND = <replaceable class="PARAMETER">initial_condition</replaceable> ] + [ , SORTOP = <replaceable class="PARAMETER">sort_operator</replaceable> ] ) </synopsis> </refsynopsisdiv> @@ -125,6 +126,29 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> ( <function>avg</function> returns null when it sees there were zero input rows. </para> + + <para> + Aggregates that behave like <function>MIN</> or <function>MAX</> can + sometimes be optimized by looking into an index instead of scanning every + input row. If this aggregate can be so optimized, indicate it by + specifying a <firstterm>sort operator</>. The basic requirement is that + the aggregate must yield the first element in the sort ordering induced by + the operator; in other words +<programlisting> +SELECT agg(col) FROM tab; +</programlisting> + must be equivalent to +<programlisting> +SELECT col FROM tab ORDER BY col USING sortop LIMIT 1; +</programlisting> + Further assumptions are that the aggregate ignores null inputs, and that + it delivers a null result if and only if there were no non-null inputs. + Ordinarily, a datatype's <literal><</> operator is the proper sort + operator for <function>MIN</>, and <literal>></> is the proper sort + operator for <function>MAX</>. Note that the optimization will never + actually take effect unless the specified operator is the LessThan or + GreaterThan strategy member of a btree index opclass. + </para> </refsect1> <refsect1> @@ -211,6 +235,19 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> ( </para> </listitem> </varlistentry> + + <varlistentry> + <term><replaceable class="PARAMETER">sort_operator</replaceable></term> + <listitem> + <para> + The associated sort operator for a <function>MIN</>- or + <function>MAX</>-like aggregate. + This is just an operator name (possibly schema-qualified). + The operator is assumed to have the same input datatypes as + the aggregate. + </para> + </listitem> + </varlistentry> </variablelist> <para> |