postgresql/contrib
Andres Freund f3d3118532 Support GROUPING SETS, CUBE and ROLLUP.
This SQL standard functionality allows to aggregate data by different
GROUP BY clauses at once. Each grouping set returns rows with columns
grouped by in other sets set to NULL.

This could previously be achieved by doing each grouping as a separate
query, conjoined by UNION ALLs. Besides being considerably more concise,
grouping sets will in many cases be faster, requiring only one scan over
the underlying data.

The current implementation of grouping sets only supports using sorting
for input. Individual sets that share a sort order are computed in one
pass. If there are sets that don't share a sort order, additional sort &
aggregation steps are performed. These additional passes are sourced by
the previous sort step; thus avoiding repeated scans of the source data.

The code is structured in a way that adding support for purely using
hash aggregation or a mix of hashing and sorting is possible. Sorting
was chosen to be supported first, as it is the most generic method of
implementation.

Instead of, as in an earlier versions of the patch, representing the
chain of sort and aggregation steps as full blown planner and executor
nodes, all but the first sort are performed inside the aggregation node
itself. This avoids the need to do some unusual gymnastics to handle
having to return aggregated and non-aggregated tuples from underlying
nodes, as well as having to shut down underlying nodes early to limit
memory usage.  The optimizer still builds Sort/Agg node to describe each
phase, but they're not part of the plan tree, but instead additional
data for the aggregation node. They're a convenient and preexisting way
to describe aggregation and sorting.  The first (and possibly only) sort
step is still performed as a separate execution step. That retains
similarity with existing group by plans, makes rescans fairly simple,
avoids very deep plans (leading to slow explains) and easily allows to
avoid the sorting step if the underlying data is sorted by other means.

A somewhat ugly side of this patch is having to deal with a grammar
ambiguity between the new CUBE keyword and the cube extension/functions
named cube (and rollup). To avoid breaking existing deployments of the
cube extension it has not been renamed, neither has cube been made a
reserved keyword. Instead precedence hacking is used to make GROUP BY
cube(..) refer to the CUBE grouping sets feature, and not the function
cube(). To actually group by a function cube(), unlikely as that might
be, the function name has to be quoted.

Needs a catversion bump because stored rules may change.

Author: Andrew Gierth and Atri Sharma, with contributions from Andres Freund
Reviewed-By: Andres Freund, Noah Misch, Tom Lane, Svenne Krap, Tomas
    Vondra, Erik Rijkers, Marti Raudsepp, Pavel Stehule
Discussion: CAOeZVidmVRe2jU6aMk_5qkxnB7dfmPROzM7Ur8JPW5j8Y5X-Lw@mail.gmail.com
2015-05-16 03:46:31 +02:00
..
adminpack Update copyright for 2015 2015-01-06 11:43:47 -05:00
auth_delay Add file version information to most installed Windows binaries. 2014-07-14 14:07:52 -04:00
auto_explain Rearrange explain.c's API so callers need not embed sizeof(ExplainState). 2015-01-15 13:39:33 -05:00
btree_gin Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
btree_gist Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
chkpass Avoid returning undefined bytes in chkpass_in(). 2015-02-14 12:20:56 -05:00
citext Fix incorrect declaration of citext's regexp_matches() functions. 2015-05-05 15:51:22 -04:00
cube Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
dblink Fix volatile-safety issue in dblink's materializeQueryResult(). 2015-01-26 15:17:33 -05:00
dict_int Update copyright for 2015 2015-01-06 11:43:47 -05:00
dict_xsyn Update copyright for 2015 2015-01-06 11:43:47 -05:00
earthdistance Improve speed of make check-world 2015-04-23 08:59:52 -04:00
file_fdw TABLESAMPLE, SQL Standard and extensible 2015-05-15 14:37:10 -04:00
fuzzystrmatch Remove dead code. 2015-02-03 09:43:44 +02:00
hstore Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
hstore_plperl Enable transforms modules to build and run with Mingw builds. 2015-05-03 09:10:47 -04:00
hstore_plpython hstore_plpython: Support tests on Python 2.3 2015-05-04 22:30:21 -04:00
intagg Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
intarray Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
isn Replace a bunch more uses of strncpy() with safer coding. 2015-01-24 13:05:42 -05:00
lo Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
ltree Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
ltree_plpython Enable transforms modules to build and run with Mingw builds. 2015-05-03 09:10:47 -04:00
oid2name Add file version information to most installed Windows binaries. 2014-07-14 14:07:52 -04:00
pageinspect Improve BRIN infra, minmax opclass and regression test 2015-05-07 13:02:22 -03:00
passwordcheck Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_audit Remove useless pg_audit.conf 2015-05-15 10:41:53 -04:00
pg_buffercache Align buffer descriptors to cache line boundaries. 2015-01-29 22:48:45 +01:00
pg_freespacemap Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pg_prewarm Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_standby pg_standby: Avoid writing one byte beyond the end of the buffer. 2015-01-15 09:26:03 -05:00
pg_stat_statements Support GROUPING SETS, CUBE and ROLLUP. 2015-05-16 03:46:31 +02:00
pg_trgm Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
pgcrypto Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
pgrowlocks Optimize locking a tuple already locked by another subxact 2015-04-10 13:47:15 -03:00
pgstattuple Add pgstattuple_approx() to the pgstattuple extension. 2015-05-13 07:35:06 +02:00
postgres_fdw TABLESAMPLE, SQL Standard and extensible 2015-05-15 14:37:10 -04:00
seg Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
sepgsql Represent columns requiring insert and update privileges indentently. 2015-05-08 00:20:46 +02:00
spi Add new OID alias type regrole 2015-05-09 13:06:49 -04:00
sslinfo Make Port->ssl_in_use available, even when built with !USE_SSL 2014-11-25 09:46:11 +02:00
start-scripts Fix typo in linux startup script. 2015-04-26 09:43:15 -04:00
tablefunc Handle unexpected query results, especially NULLs, safely in connectby(). 2015-01-29 20:18:33 -05:00
tcn Update copyright for 2015 2015-01-06 11:43:47 -05:00
test_decoding Replace some appendStringInfo* calls with more appropriate variants 2015-05-11 20:38:55 -04:00
tsearch2 Update copyright for 2015 2015-01-06 11:43:47 -05:00
tsm_system_rows contrib/tsm_system_rows 2015-05-15 15:31:14 -04:00
tsm_system_time contrib/tsm_system_time 2015-05-15 15:31:50 -04:00
unaccent Update copyright for 2015 2015-01-06 11:43:47 -05:00
uuid-ossp Update copyright for 2015 2015-01-06 11:43:47 -05:00
vacuumlo vacuumlo: Avoid unlikely memory leak. 2015-01-14 15:14:20 -05:00
xml2 Replace a bunch more uses of strncpy() with safer coding. 2015-01-24 13:05:42 -05:00
Makefile Add to contrib/Makefile 2015-05-15 15:33:37 -04:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00
contrib-global.mk Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00

README

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.