Date: Mon, 14 Oct 2019 10:42:42 -0700
Subject: [PATCH] docs - aggregate-related updates (#8759)
* docs - update pg_aggregate and related aggregate sql commands
* planner supports ordered-set aggregates
* add missing periods
---
.../query/topics/functions-operators.xml | 3 +-
.../topics/query-piv-opt-limitations.xml | 3 +-
.../sql_commands/ALTER_AGGREGATE.xml | 47 ++++-
.../sql_commands/ALTER_EXTENSION.xml | 6 +-
.../dita/ref_guide/sql_commands/COMMENT.xml | 20 +-
.../sql_commands/CREATE_AGGREGATE.xml | 48 +++--
.../ref_guide/sql_commands/DROP_AGGREGATE.xml | 49 ++++-
.../system_catalogs/pg_aggregate.xml | 197 ++++++++++++++++--
8 files changed, 297 insertions(+), 76 deletions(-)
diff --git a/gpdb-doc/dita/admin_guide/query/topics/functions-operators.xml b/gpdb-doc/dita/admin_guide/query/topics/functions-operators.xml
index de574e2f16..4f2778f1c2 100644
--- a/gpdb-doc/dita/admin_guide/query/topics/functions-operators.xml
+++ b/gpdb-doc/dita/admin_guide/query/topics/functions-operators.xml
@@ -783,8 +783,7 @@ SELECT foo();
Advanced Aggregate Functions
The following built-in advanced aggregate functions are Greenplum extensions of the
- PostgreSQL database. These functions are immutable. Greenplum Database does
- not support the PostgreSQL ordered-set aggregate functions.
+ PostgreSQL database. These functions are immutable.
The Greenplum MADlib Extension for Analytics provides additional advanced
functions to perform statistical analysis and machine learning with Greenplum
Database data. See FIELDSELECT
Aggregate functions that take set operators as input arguments.
- percentile_* window functions (Greenplum Database does not support
- ordered-set aggregate functions).
+ percentile_* window functions (ordered-set aggregate functions).
Inverse distribution functions.
Queries that execute functions that are defined with the ON MASTER or
ON ALL SEGMENTS attribute.
diff --git a/gpdb-doc/dita/ref_guide/sql_commands/ALTER_AGGREGATE.xml b/gpdb-doc/dita/ref_guide/sql_commands/ALTER_AGGREGATE.xml
index 7040c8657b..e432ae48e0 100644
--- a/gpdb-doc/dita/ref_guide/sql_commands/ALTER_AGGREGATE.xml
+++ b/gpdb-doc/dita/ref_guide/sql_commands/ALTER_AGGREGATE.xml
@@ -1,11 +1,16 @@
-ALTER AGGREGATEChanges the definition of an aggregate function
SynopsisALTER AGGREGATE name ( type [ , ... ] ) RENAME TO new_name
+ALTER AGGREGATEChanges the definition of an aggregate function
SynopsisALTER AGGREGATE name ( aggregate_signature ) RENAME TO new_name
-ALTER AGGREGATE name ( type [ , ... ] ) OWNER TO new_owner
+ALTER AGGREGATE name ( aggregate_signature ) OWNER TO new_owner
-ALTER AGGREGATE name ( type [ , ... ] ) SET SCHEMA new_schemaDescriptionALTER AGGREGATE changes the definition of an aggregate
+ALTER AGGREGATE name ( aggregate_signature ) SET SCHEMA new_schema
+where aggregate_signature is:
+ * |
+[ argmode ] [ argname ] argtype [ , ... ] |
+[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
+DescriptionALTER AGGREGATE changes the definition of an aggregate
function.
You must own the aggregate function to use ALTER AGGREGATE.
To change the schema of an aggregate function, you must also have CREATE
privilege on the new schema. To alter the owner, you must also be a direct
@@ -14,9 +19,39 @@ privilege on the aggregate function's schema. (These restrictions enforce
that altering the owner does not do anything you could not do by dropping
and recreating the aggregate function. However, a superuser can alter
ownership of any aggregate function anyway.)
ParametersnameThe name (optionally schema-qualified) of an existing aggregate function.
-typeAn input data type on which the aggregate function operates. To reference
-a zero-argument aggregate function, write * in place of the list of input
-data types. new_nameThe new name of the aggregate function. new_ownerThe new owner of the aggregate function. new_schemaThe new schema for the aggregate function.ExamplesTo rename the aggregate function myavg for type integer to
+
+
+ argmode
+ The mode of an argument: IN or VARIADIC.
+ If omitted, the default is IN.
+
+
+ argname
+ The name of an argument. Note that ALTER AGGREGATE does not
+ actually pay any attention to argument names, since only the argument data types
+ are needed to determine the aggregate function's identity.
+
+
+ argtype
+ An input data type on which the aggregate function operates. To reference
+ a zero-argument aggregate function, write * in place of the
+ list of input data types. To reference an ordered-set aggregate function, write
+ ORDER BY between the direct and aggregated argument
+ specifications.
+
+new_nameThe new name of the aggregate function. new_ownerThe new owner of the aggregate function. new_schemaThe new schema for the aggregate function.
+
+ Notes
+ The recommended syntax for referencing an ordered-set aggregate is to write
+ ORDER BY between the direct and aggregated argument specifications,
+ in the same style as in
+ .
+ However, it will also work to omit ORDER BY and just run the
+ direct and aggregated argument specifications into a single list. In this
+ abbreviated form, if VARIADIC "any" was used in both the direct
+ and aggregated argument lists, write VARIADIC "any" only once.
+
+ExamplesTo rename the aggregate function myavg for type integer to
my_average:
ALTER AGGREGATE myavg(integer) RENAME TO my_average;To change the owner of the aggregate function myavg for type
integer to joe:
ALTER AGGREGATE myavg(integer) OWNER TO joe;To move the aggregate function myavg for type integer into
schema myschema:
ALTER AGGREGATE myavg(integer) SET SCHEMA myschema;CompatibilityThere is no ALTER AGGREGATE statement in the SQL standard.
See Also,
diff --git a/gpdb-doc/dita/ref_guide/sql_commands/ALTER_EXTENSION.xml b/gpdb-doc/dita/ref_guide/sql_commands/ALTER_EXTENSION.xml
index 553ce53b9f..a03f90a17b 100644
--- a/gpdb-doc/dita/ref_guide/sql_commands/ALTER_EXTENSION.xml
+++ b/gpdb-doc/dita/ref_guide/sql_commands/ALTER_EXTENSION.xml
@@ -44,9 +44,9 @@ where member_object is:
and aggregate_signature is:
-* | [ argmode ] [ argname ] argtype [ , ... ] |
- [ [ argmode ] [ argname ] argtype [ , ... ] ]
- ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
+* |
+[ argmode ] [ argname ] argtype [ , ... ] |
+[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
Description
diff --git a/gpdb-doc/dita/ref_guide/sql_commands/COMMENT.xml b/gpdb-doc/dita/ref_guide/sql_commands/COMMENT.xml
index 9ddfd5e210..be9dd5a2b1 100644
--- a/gpdb-doc/dita/ref_guide/sql_commands/COMMENT.xml
+++ b/gpdb-doc/dita/ref_guide/sql_commands/COMMENT.xml
@@ -10,7 +10,7 @@
COMMENT ON
{ TABLE object_name |
COLUMN relation_name.column_name |
- AGGREGATE agg_name (agg_type [, ...]) |
+ AGGREGATE agg_name (agg_signature) |
CAST (source_type AS target_type) |
COLLATION object_name
CONSTRAINT constraint_name ON table_name |
@@ -38,6 +38,10 @@
TYPE object_name |
VIEW object_name }
IS 'text'
+where agg_signature is:
+* |
+[ argmode ] [ argname ] argtype [ , ... ] |
+[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
Description
@@ -73,12 +77,6 @@ IS 'text'
refer to a table, view, composite type, or foreign table.Greenplum Database does
not support triggers.
-
- aggregate_type
- An input data type on which the aggregate function operates. To reference a
- zero-argument aggregate function, write * in place of the list of input
- data types.
-
source_type
The name of the source data type of the cast.
@@ -89,9 +87,9 @@ IS 'text'
argmode
- The mode of a function argument: either IN, OUT,
+ The mode of a function or aggregate argument: either IN, OUT,
INOUT, or VARIADIC. If omitted, the default is
- IN. Note that COMMENT ON FUNCTION does not actually
+ IN. Note that COMMENT does not actually
pay any attention to OUT arguments, since only the input arguments are
needed to determine the function's identity. So it is sufficient to list the
IN, INOUT, and VARIADIC arguments.
@@ -99,13 +97,13 @@ IS 'text'
argname
- The name of a function argument. Note that COMMENT ON FUNCTION does
+ The name of a function or aggregate argument. Note that COMMENT ON FUNCTION does
not actually pay any attention to argument names, since only the argument data types are
needed to determine the function's identity.
argtype
- The data type(s) of the function's arguments (optionally schema-qualified), if any.
+ The data type of a function or aggregate argument.
diff --git a/gpdb-doc/dita/ref_guide/sql_commands/CREATE_AGGREGATE.xml b/gpdb-doc/dita/ref_guide/sql_commands/CREATE_AGGREGATE.xml
index cf136bb213..5c058569a7 100644
--- a/gpdb-doc/dita/ref_guide/sql_commands/CREATE_AGGREGATE.xml
+++ b/gpdb-doc/dita/ref_guide/sql_commands/CREATE_AGGREGATE.xml
@@ -6,7 +6,7 @@
Defines a new aggregate function.
SynopsisargnameCREATE AGGREGATE name ( [ argmode ] [ ] arg_data_type [ , ... ] ) (
+ >SynopsisCREATE AGGREGATE name ( [ argmode ] [ argname ] arg_data_type [ , ... ] ) (
SFUNC = statefunc,
STYPE = state_data_type
[ , SSPACE = state_data_size ]
@@ -126,7 +126,8 @@
single-level aggregation that sends all the rows to the master and then applies only the
statefunc to the rows.
An aggregate function can provide an optional initial condition, an initial value for the
- internal state value. This is specified and stored in the database as a value of type text,
+ internal state value. This is specified and stored in the database as a value of type
+ text,
but it must be a valid external representation of a constant of the state value data type.
If it is not supplied then the state value starts out NULL.
If statefunc is declared STRICT,
@@ -138,11 +139,11 @@
subsequent rows with all non-null input values. This is useful for implementing aggregates
like max. Note that this behavior is only available when
state_data_type is the same as the first
- input_data_type. When these types are different, you must supply a
+ arg_data_type. When these types are different, you must supply a
non-null initial condition or use a nonstrict transition function.
If statefunc is not declared STRICT, then it will be
called unconditionally at each input row, and must deal with NULL inputs
- and NULL transition values for itself. This allows the aggregate author to
+ and NULL state values for itself. This allows the aggregate author to
have full control over the aggregate's handling of NULL values.
If the final function (ffunc) is declared
STRICT, then it will not be called when the ending state value is
@@ -164,7 +165,7 @@
href="https://www.postgresql.org/docs/9.4/xaggr.html#XAGGR-MOVING-AGGREGATES"
scope="external" format="html">Moving-Aggregate Mode in the PostgreSQL
documentation. This requires specifying the msfunc,
- minfunc, and
+ minvfunc, and
mstype functions, and optionally the
mspace,
mfinalfunc,
@@ -184,9 +185,10 @@
direct arguments are required to match, in number and data types, the aggregated argument
columns. This allows the values of those direct arguments to be added to the collection of
aggregate-input rows as an additional "hypothetical" row.
- Single argument aggregate functions, such as min or max, can sometimes be optimized by
+
Single argument aggregate functions, such as min or
+ 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 sort operator. The basic requirement is that the
+ optimized, indicate it by specifying a 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:
SELECT agg(col) FROM tab;
@@ -200,7 +202,7 @@
the specified operator is the "less than" or "greater than" strategy member of a B-tree
index operator class.