You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
(28) |
Jun
(12) |
Jul
(11) |
Aug
(12) |
Sep
(5) |
Oct
(19) |
Nov
(14) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(18) |
Feb
(30) |
Mar
(115) |
Apr
(89) |
May
(50) |
Jun
(44) |
Jul
(22) |
Aug
(13) |
Sep
(11) |
Oct
(30) |
Nov
(28) |
Dec
(39) |
2012 |
Jan
(38) |
Feb
(18) |
Mar
(43) |
Apr
(91) |
May
(108) |
Jun
(46) |
Jul
(37) |
Aug
(44) |
Sep
(33) |
Oct
(29) |
Nov
(36) |
Dec
(15) |
2013 |
Jan
(35) |
Feb
(611) |
Mar
(5) |
Apr
(55) |
May
(30) |
Jun
(28) |
Jul
(458) |
Aug
(34) |
Sep
(9) |
Oct
(39) |
Nov
(22) |
Dec
(32) |
2014 |
Jan
(16) |
Feb
(16) |
Mar
(42) |
Apr
(179) |
May
(7) |
Jun
(6) |
Jul
(9) |
Aug
|
Sep
(4) |
Oct
|
Nov
(3) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
|
1
|
2
|
3
|
4
|
5
(2) |
6
(2) |
7
|
8
(2) |
9
|
10
|
11
(1) |
12
(1) |
13
|
14
(2) |
15
(2) |
16
|
17
|
18
(1) |
19
|
20
|
21
(2) |
22
|
23
|
24
|
25
(1) |
26
|
27
(2) |
28
(2) |
29
(2) |
30
|
31
|
|
|
|
|
|
|
From: Michael P. <mic...@us...> - 2011-07-08 07:01:19
|
Project "Postgres-XC". The branch, master has been updated via 4eb6e0b9b6d0a1d75ade7c80b2d22f64e8a84544 (commit) from 28f420edd65be1966f96bce37893a93f5cf10470 (commit) - Log ----------------------------------------------------------------- commit 4eb6e0b9b6d0a1d75ade7c80b2d22f64e8a84544 Author: Michael P <mic...@us...> Date: Fri Jul 8 15:55:21 2011 +0900 Improvement of expression push-down analysis to foreign servers This patch controls expressions by using the functionalities of XC's foreign data wrapper analysis functions. Basically, immutable functions/operators can be safely pushed down as well as arrays, constant values, booleans, external parameters, etc. For functions and operators, the expression can be pushed down if it has the same meaning for local and foreign server. This commit also cleans up a part of PGXC planner. diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 5022e84..7b28b89 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -39,6 +39,7 @@ #ifdef PGXC #include "pgxc/pgxc.h" #include "pgxc/planner.h" +#include "pgxc/postgresql_fdw.h" #include "access/sysattr.h" #include "utils/builtins.h" #include "utils/syscache.h" @@ -191,7 +192,6 @@ static Material *make_material(Plan *lefttree); #ifdef PGXC static void findReferencedVars(List *parent_vars, Plan *plan, List **out_tlist, Relids *out_relids); -extern bool is_foreign_qual(Node *clause); static void create_remote_clause_expr(PlannerInfo *root, Plan *parent, StringInfo clauses, List *qual, RemoteQuery *scan); static void create_remote_expr(PlannerInfo *root, Plan *parent, StringInfo expr, diff --git a/src/backend/pgxc/plan/planner.c b/src/backend/pgxc/plan/planner.c index 1cd33d1..098f8c9 100644 --- a/src/backend/pgxc/plan/planner.c +++ b/src/backend/pgxc/plan/planner.c @@ -36,6 +36,7 @@ #include "pgxc/pgxc.h" #include "pgxc/locator.h" #include "pgxc/planner.h" +#include "pgxc/postgresql_fdw.h" #include "tcop/pquery.h" #include "utils/acl.h" #include "utils/builtins.h" @@ -170,7 +171,6 @@ static int handle_limit_offset(RemoteQuery *query_step, Query *query, PlannedStm static void InitXCWalkerContext(XCWalkerContext *context); static RemoteQuery *makeRemoteQuery(void); static void validate_part_col_updatable(const Query *query); -static bool is_pgxc_safe_func(Oid funcid); /* @@ -1239,6 +1239,13 @@ examine_conditions_walker(Node *expr_node, XCWalkerContext *context) */ return false; } + else + { + /* Check if this node can be pushed down. */ + if (!is_foreign_qual((Node *) arg2)) + return true; + } + /* * Check if it is an expression like pcol = expr, where pcol is * a partitioning column of the rel1 and planner could not @@ -1267,13 +1274,19 @@ examine_conditions_walker(Node *expr_node, XCWalkerContext *context) return false; } } + else + { + /* Check if this node can be pushed down. */ + if (!is_foreign_qual((Node *) arg2)) + return true; + } } } /* See if the function is immutable, otherwise give up */ if (IsA(expr_node, FuncExpr)) { - if (!is_pgxc_safe_func(((FuncExpr*) expr_node)->funcid)) + if (!is_foreign_qual((Node *) expr_node)) return true; } @@ -3143,64 +3156,6 @@ validate_part_col_updatable(const Query *query) } } -/* - * See if it is safe to use this function in single step. - * - * Based on is_immutable_func from postgresql_fdw.c - * We add an exeption for base postgresql functions, to - * allow now() and others to still execute as part of single step - * queries. - * - * PGXCTODO - we currently make the false assumption that immutable - * functions will not write to the database. This could be addressed - * by either a more thorough analysis of functions at - * creation time or additional tags at creation time (preferably - * in standard PostgreSQL). Ideally such functionality could be - * committed back to standard PostgreSQL. - */ -bool -is_pgxc_safe_func(Oid funcid) -{ - HeapTuple tp; - bool isnull; - Datum datum; - bool ret_val = false; - - tp = SearchSysCache(PROCOID, ObjectIdGetDatum(funcid), 0, 0, 0); - if (!HeapTupleIsValid(tp)) - elog(ERROR, "cache lookup failed for function %u", funcid); - -#ifdef DEBUG_FDW - /* print function name and its immutability */ - { - char *proname; - datum = SysCacheGetAttr(PROCOID, tp, Anum_pg_proc_proname, &isnull); - proname = pstrdup(DatumGetName(datum)->data); - elog(DEBUG1, "func %s(%u) is%s immutable", proname, funcid, - (DatumGetChar(datum) == PROVOLATILE_IMMUTABLE) ? "" : " not"); - pfree(proname); - } -#endif - - datum = SysCacheGetAttr(PROCOID, tp, Anum_pg_proc_provolatile, &isnull); - - if (DatumGetChar(datum) == PROVOLATILE_IMMUTABLE) - ret_val = true; - /* - * Also allow stable and volatile ones that are in the PG_CATALOG_NAMESPACE - * this allows now() and others that do not update the database - * PGXCTODO - examine default functions carefully for those that may - * write to the database. - */ - else - { - datum = SysCacheGetAttr(PROCOID, tp, Anum_pg_proc_pronamespace, &isnull); - if (DatumGetObjectId(datum) == PG_CATALOG_NAMESPACE) - ret_val = true; - } - ReleaseSysCache(tp); - return ret_val; -} /* * GetHashExecNodes - diff --git a/src/backend/pgxc/pool/postgresql_fdw.c b/src/backend/pgxc/pool/postgresql_fdw.c index 93c30b2..1a158a6 100644 --- a/src/backend/pgxc/pool/postgresql_fdw.c +++ b/src/backend/pgxc/pool/postgresql_fdw.c @@ -10,30 +10,25 @@ * *------------------------------------------------------------------------- */ -#include "postgres.h" - +#include "pgxc/postgresql_fdw.h" #include "catalog/pg_operator.h" #include "catalog/pg_proc.h" #include "funcapi.h" -//#include "libpq-fe.h" #include "mb/pg_wchar.h" #include "miscadmin.h" #include "nodes/nodeFuncs.h" #include "nodes/makefuncs.h" #include "optimizer/clauses.h" #include "parser/scansup.h" -#include "pgxc/execRemote.h" #include "utils/builtins.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/syscache.h" -//#include "dblink.h" - #define DEBUG_FDW /* - * WHERE caluse optimization level + * WHERE clause optimization level */ #define EVAL_QUAL_LOCAL 0 /* evaluate none in foreign, all in local */ #define EVAL_QUAL_BOTH 1 /* evaluate some in foreign, all in local */ @@ -41,14 +36,8 @@ #define OPTIMIZE_WHERE_CLAUSE EVAL_QUAL_FOREIGN - - /* deparse SQL from the request */ -bool is_immutable_func(Oid funcid); -bool is_foreign_qual(Node *node); static bool foreign_qual_walker(Node *node, void *context); -char *deparseSql(RemoteQueryState *scanstate); - /* * Check whether the function is IMMUTABLE. diff --git a/src/include/pgxc/planner.h b/src/include/pgxc/planner.h index 1a18c9f..4228fbf 100644 --- a/src/include/pgxc/planner.h +++ b/src/include/pgxc/planner.h @@ -138,8 +138,6 @@ extern PlannedStmt *pgxc_planner(Query *query, int cursorOptions, extern Plan *pgxc_grouping_planner(PlannerInfo *root, Plan *agg_plan); extern bool IsHashDistributable(Oid col_type); -extern bool is_immutable_func(Oid funcid); - extern bool IsJoinReducible(RemoteQuery *innernode, RemoteQuery *outernode, List *rtable_list, JoinPath *join_path, JoinReduceInfo *join_info); diff --git a/src/include/pgxc/postgresql_fdw.h b/src/include/pgxc/postgresql_fdw.h new file mode 100644 index 0000000..563236c --- /dev/null +++ b/src/include/pgxc/postgresql_fdw.h @@ -0,0 +1,24 @@ +/*------------------------------------------------------------------------- + * + * postgresql_fdw.h + * + * foreign-data wrapper for PostgreSQL + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $PostgreSQL$ + * + *------------------------------------------------------------------------- + */ + +#ifndef POSTGRES_FDW_H +#define POSTGRES_FDW_H + +#include "postgres.h" +#include "pgxc/execRemote.h" + +bool is_immutable_func(Oid funcid); +bool is_foreign_qual(Node *node); +char *deparseSql(RemoteQueryState *scanstate); +#endif ----------------------------------------------------------------------- Summary of changes: src/backend/optimizer/plan/createplan.c | 2 +- src/backend/pgxc/plan/planner.c | 75 ++++++------------------------ src/backend/pgxc/pool/postgresql_fdw.c | 15 +----- src/include/pgxc/planner.h | 2 - src/include/pgxc/postgresql_fdw.h | 24 ++++++++++ 5 files changed, 42 insertions(+), 76 deletions(-) create mode 100644 src/include/pgxc/postgresql_fdw.h hooks/post-receive -- Postgres-XC |
From: Ashutosh B. <ash...@us...> - 2011-07-08 06:17:53
|
Project "Postgres-XC". The branch, master has been updated via 28f420edd65be1966f96bce37893a93f5cf10470 (commit) from e1083f299ae559b26ad1b224f8452ef4d697d23e (commit) - Log ----------------------------------------------------------------- commit 28f420edd65be1966f96bce37893a93f5cf10470 Author: Ashutosh Bapat <ash...@en...> Date: Fri Jul 8 11:39:04 2011 +0530 Due to merge from PG9.1, we have tests xc_groupby and xc_having fail because of following reasons 1. The test alter_table.sql creates two tables tab1 and tab2, but does not drop them. When tests xc_groupby and xc_having create tables with same names, the table creation and subsequently all the queries against these tables fail. Changed the names of these tables to have test names as prefixes. 2. There were planner and costing changes in PG9.1, hence many of the EXPLAIN VERBOSE outputs changed. Fixed the expected outputs for the same. diff --git a/src/test/regress/expected/xc_groupby.out b/src/test/regress/expected/xc_groupby.out index 31e9a8c..08f8da5 100644 --- a/src/test/regress/expected/xc_groupby.out +++ b/src/test/regress/expected/xc_groupby.out @@ -6,11 +6,11 @@ -- Combination 1: enable_hashagg on and distributed tables set enable_hashagg to on; -- create required tables and fill them with data -create table tab1 (val int, val2 int); -create table tab2 (val int, val2 int); -insert into tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 group by val2; +create table xc_groupby_tab1 (val int, val2 int); +create table xc_groupby_tab2 (val int, val2 int); +insert into xc_groupby_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); +insert into xc_groupby_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); +select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_groupby_tab1 group by val2; count | sum | avg | ?column? | val2 -------+-----+--------------------+------------------+------ 3 | 6 | 2.0000000000000000 | 2 | 1 @@ -18,10 +18,10 @@ select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 g 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 (3 rows) -explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 group by val2; +explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_groupby_tab1 group by val2; QUERY PLAN ------------------------------------------------------------------------------------------------------------- - HashAggregate (cost=1.03..1.06 rows=1 width=8) + HashAggregate (cost=1.03..1.05 rows=1 width=8) Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) Output: val, val2 @@ -30,7 +30,7 @@ explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), (6 rows) -- joins and group by -select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val*tab2.val)::float8/count(*), tab1.val2, tab2.val2 from tab1 full outer join tab2 on tab1.val2 = tab2.val2 group by tab1.val2, tab2.val2; +select count(*), sum(xc_groupby_tab1.val * xc_groupby_tab2.val), avg(xc_groupby_tab1.val*xc_groupby_tab2.val), sum(xc_groupby_tab1.val*xc_groupby_tab2.val)::float8/count(*), xc_groupby_tab1.val2, xc_groupby_tab2.val2 from xc_groupby_tab1 full outer join xc_groupby_tab2 on xc_groupby_tab1.val2 = xc_groupby_tab2.val2 group by xc_groupby_tab1.val2, xc_groupby_tab2.val2; count | sum | avg | ?column? | val2 | val2 -------+-----+---------------------+------------------+------+------ 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 @@ -39,53 +39,49 @@ select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val* 3 | | | | | 4 (4 rows) -explain verbose select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val*tab2.val)::float8/count(*), tab1.val2, tab2.val2 from tab1 full outer join tab2 on tab1.val2 = tab2.val2 group by tab1.val2, tab2.val2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate (cost=2.09..2.13 rows=1 width=16) - Output: count(*), sum((tab1.val * tab2.val)), avg((tab1.val * tab2.val)), ((sum((tab1.val * tab2.val)))::double precision / (count(*))::double precision), tab1.val2, tab2.val2 - -> Merge Full Join (cost=2.05..2.07 rows=1 width=16) - Output: tab1.val, tab1.val2, tab2.val, tab2.val2 - Merge Cond: (tab1.val2 = tab2.val2) - -> Sort (cost=1.02..1.03 rows=1 width=8) - Output: tab1.val, tab1.val2 - Sort Key: tab1.val2 +explain verbose select count(*), sum(xc_groupby_tab1.val * xc_groupby_tab2.val), avg(xc_groupby_tab1.val*xc_groupby_tab2.val), sum(xc_groupby_tab1.val*xc_groupby_tab2.val)::float8/count(*), xc_groupby_tab1.val2, xc_groupby_tab2.val2 from xc_groupby_tab1 full outer join xc_groupby_tab2 on xc_groupby_tab1.val2 = xc_groupby_tab2.val2 group by xc_groupby_tab1.val2, xc_groupby_tab2.val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + HashAggregate (cost=2.08..2.10 rows=1 width=16) + Output: count(*), sum((xc_groupby_tab1.val * xc_groupby_tab2.val)), avg((xc_groupby_tab1.val * xc_groupby_tab2.val)), ((sum((xc_groupby_tab1.val * xc_groupby_tab2.val)))::double precision / (count(*))::double precision), xc_groupby_tab1.val2, xc_groupby_tab2.val2 + -> Hash Full Join (cost=1.03..2.06 rows=1 width=16) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2, xc_groupby_tab2.val, xc_groupby_tab2.val2 + Hash Cond: (xc_groupby_tab1.val2 = xc_groupby_tab2.val2) + -> Materialize (cost=0.00..1.01 rows=1 width=8) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2 + -> Data Node Scan (Node Count [2]) on xc_groupby_tab1 (cost=0.00..1.01 rows=1000 width=8) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2 + -> Hash (cost=1.01..1.01 rows=1 width=8) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) - Output: tab1.val, tab1.val2 - -> Data Node Scan (Node Count [2]) on tab1 (cost=0.00..1.01 rows=1000 width=8) - Output: tab1.val, tab1.val2 - -> Sort (cost=1.02..1.03 rows=1 width=8) - Output: tab2.val, tab2.val2 - Sort Key: tab2.val2 - -> Materialize (cost=0.00..1.01 rows=1 width=8) - Output: tab2.val, tab2.val2 - -> Data Node Scan (Node Count [2]) on tab2 (cost=0.00..1.01 rows=1000 width=8) - Output: tab2.val, tab2.val2 -(19 rows) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 + -> Data Node Scan (Node Count [2]) on xc_groupby_tab2 (cost=0.00..1.01 rows=1000 width=8) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 +(15 rows) -- aggregates over aggregates -select sum(y) from (select sum(val) y, val2%2 x from tab1 group by val2) q1 group by x; +select sum(y) from (select sum(val) y, val2%2 x from xc_groupby_tab1 group by val2) q1 group by x; sum ----- 8 17 (2 rows) -explain verbose select sum(y) from (select sum(val) y, val2%2 x from tab1 group by val2) q1 group by x; - QUERY PLAN ----------------------------------------------------------------------------------------- +explain verbose select sum(y) from (select sum(val) y, val2%2 x from xc_groupby_tab1 group by val2) q1 group by x; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.05..1.06 rows=1 width=12) - Output: sum((pg_catalog.sum((sum(tab1.val))))), ((tab1.val2 % 2)) + Output: sum((pg_catalog.sum((sum(xc_groupby_tab1.val))))), ((xc_groupby_tab1.val2 % 2)) -> HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: pg_catalog.sum((sum(tab1.val))), ((tab1.val2 % 2)), tab1.val2 + Output: pg_catalog.sum((sum(xc_groupby_tab1.val))), ((xc_groupby_tab1.val2 % 2)), xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(tab1.val)), ((tab1.val2 % 2)), tab1.val2 + Output: (sum(xc_groupby_tab1.val)), ((xc_groupby_tab1.val2 % 2)), xc_groupby_tab1.val2 -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=8) - Output: sum(tab1.val), (tab1.val2 % 2), tab1.val2 + Output: sum(xc_groupby_tab1.val), (xc_groupby_tab1.val2 % 2), xc_groupby_tab1.val2 (8 rows) -- group by without aggregate -select val2 from tab1 group by val2; +select val2 from xc_groupby_tab1 group by val2; val2 ------ 1 @@ -93,18 +89,18 @@ select val2 from tab1 group by val2; 3 (3 rows) -explain verbose select val2 from tab1 group by val2; +explain verbose select val2 from xc_groupby_tab1 group by val2; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=4) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 (6 rows) -select val + val2 from tab1 group by val + val2; +select val + val2 from xc_groupby_tab1 group by val + val2; ?column? ---------- 4 @@ -115,18 +111,18 @@ select val + val2 from tab1 group by val + val2; 2 (6 rows) -explain verbose select val + val2 from tab1 group by val + val2; +explain verbose select val + val2 from xc_groupby_tab1 group by val + val2; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: ((tab1.val + tab1.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab1.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)) -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=8) - Output: (tab1.val + tab1.val2) + Output: (xc_groupby_tab1.val + xc_groupby_tab1.val2) (6 rows) -select val + val2, val, val2 from tab1 group by val, val2; +select val + val2, val, val2 from xc_groupby_tab1 group by val, val2; ?column? | val | val2 ----------+-----+------ 7 | 4 | 3 @@ -139,18 +135,18 @@ select val + val2, val, val2 from tab1 group by val, val2; 9 | 6 | 3 (8 rows) -explain verbose select val + val2, val, val2 from tab1 group by val, val2; - QUERY PLAN ----------------------------------------------------------------------------------- +explain verbose select val + val2, val, val2 from xc_groupby_tab1 group by val, val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: ((tab1.val + tab1.val2)), tab1.val, tab1.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)), xc_groupby_tab1.val, xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab1.val2)), tab1.val, tab1.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)), xc_groupby_tab1.val, xc_groupby_tab1.val2 -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=8) - Output: (tab1.val + tab1.val2), tab1.val, tab1.val2 + Output: (xc_groupby_tab1.val + xc_groupby_tab1.val2), xc_groupby_tab1.val, xc_groupby_tab1.val2 (6 rows) -select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val, tab2.val2; +select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2; ?column? | val | val2 ----------+-----+------ 5 | 3 | 2 @@ -161,18 +157,18 @@ select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val 7 | 3 | 4 (6 rows) -explain verbose select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val, tab2.val2; - QUERY PLAN -------------------------------------------------------------------------------- +explain verbose select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- HashAggregate (cost=0.00..0.01 rows=1 width=0) - Output: ((tab1.val + tab2.val2)), tab1.val, tab2.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)), xc_groupby_tab1.val, xc_groupby_tab2.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab2.val2)), tab1.val, tab2.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)), xc_groupby_tab1.val, xc_groupby_tab2.val2 -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1 width=4) - Output: (tab1.val + tab2.val2), tab1.val, tab2.val2 + Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2 (6 rows) -select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val + tab2.val2; +select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2; ?column? ---------- 6 @@ -181,19 +177,19 @@ select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by t 5 (4 rows) -explain verbose select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val + tab2.val2; +explain verbose select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2; QUERY PLAN ------------------------------------------------------------------------------- HashAggregate (cost=0.00..0.01 rows=1 width=0) - Output: ((tab1.val + tab2.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab2.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)) -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1 width=4) - Output: (tab1.val + tab2.val2) + Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2) (6 rows) -- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; +select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2; ?column? | val2 ---------------------+------ 11.0000000000000000 | 1 @@ -201,10 +197,10 @@ select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; 17.6666666666666667 | 3 (3 rows) -explain verbose select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; +explain verbose select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2; QUERY PLAN ---------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.05 rows=1 width=8) + HashAggregate (cost=1.02..1.04 rows=1 width=8) Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) Output: val, val2 @@ -213,7 +209,7 @@ explain verbose select count(*) + sum(val) + avg(val), val2 from tab1 group by v (6 rows) -- group by with expressions in group by clause -select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; +select sum(val), avg(val), 2 * val2 from xc_groupby_tab1 group by 2 * val2; sum | avg | ?column? -----+--------------------+---------- 11 | 3.6666666666666667 | 6 @@ -221,35 +217,35 @@ select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; 8 | 4.0000000000000000 | 4 (3 rows) -explain verbose select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; - QUERY PLAN ------------------------------------------------------------------------------------------------ +explain verbose select sum(val), avg(val), 2 * val2 from xc_groupby_tab1 group by 2 * val2; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.04 rows=1 width=8) - Output: pg_catalog.sum((sum(tab1.val))), pg_catalog.avg((avg(tab1.val))), ((2 * tab1.val2)) + Output: pg_catalog.sum((sum(xc_groupby_tab1.val))), pg_catalog.avg((avg(xc_groupby_tab1.val))), ((2 * xc_groupby_tab1.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(tab1.val)), (avg(tab1.val)), ((2 * tab1.val2)) + Output: (sum(xc_groupby_tab1.val)), (avg(xc_groupby_tab1.val)), ((2 * xc_groupby_tab1.val2)) -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=8) - Output: sum(tab1.val), avg(tab1.val), (2 * tab1.val2) + Output: sum(xc_groupby_tab1.val), avg(xc_groupby_tab1.val), (2 * xc_groupby_tab1.val2) (6 rows) -drop table tab1; -drop table tab2; +drop table xc_groupby_tab1; +drop table xc_groupby_tab2; -- some tests involving nulls, characters, float type etc. -create table def(a int, b varchar(25)); -insert into def VALUES (NULL, NULL); -insert into def VALUES (1, NULL); -insert into def VALUES (NULL, 'One'); -insert into def VALUES (2, 'Two'); -insert into def VALUES (2, 'Two'); -insert into def VALUES (3, 'Three'); -insert into def VALUES (4, 'Three'); -insert into def VALUES (5, 'Three'); -insert into def VALUES (6, 'Two'); -insert into def VALUES (7, NULL); -insert into def VALUES (8, 'Two'); -insert into def VALUES (9, 'Three'); -insert into def VALUES (10, 'Three'); -select a,count(a) from def group by a order by a; +create table xc_groupby_def(a int, b varchar(25)); +insert into xc_groupby_def VALUES (NULL, NULL); +insert into xc_groupby_def VALUES (1, NULL); +insert into xc_groupby_def VALUES (NULL, 'One'); +insert into xc_groupby_def VALUES (2, 'Two'); +insert into xc_groupby_def VALUES (2, 'Two'); +insert into xc_groupby_def VALUES (3, 'Three'); +insert into xc_groupby_def VALUES (4, 'Three'); +insert into xc_groupby_def VALUES (5, 'Three'); +insert into xc_groupby_def VALUES (6, 'Two'); +insert into xc_groupby_def VALUES (7, NULL); +insert into xc_groupby_def VALUES (8, 'Two'); +insert into xc_groupby_def VALUES (9, 'Three'); +insert into xc_groupby_def VALUES (10, 'Three'); +select a,count(a) from xc_groupby_def group by a order by a; a | count ----+------- 1 | 1 @@ -265,14 +261,14 @@ select a,count(a) from def group by a order by a; | 0 (11 rows) -explain verbose select a,count(a) from def group by a order by a; +explain verbose select a,count(a) from xc_groupby_def group by a order by a; QUERY PLAN ---------------------------------------------------------------------------------------------- - GroupAggregate (cost=1.02..1.05 rows=1 width=4) + GroupAggregate (cost=1.02..1.04 rows=1 width=4) Output: a, count(a) -> Sort (cost=1.02..1.03 rows=1 width=4) Output: a - Sort Key: def.a + Sort Key: xc_groupby_def.a -> Result (cost=0.00..1.01 rows=1 width=4) Output: a -> Materialize (cost=0.00..1.01 rows=1 width=4) @@ -281,7 +277,7 @@ explain verbose select a,count(a) from def group by a order by a; Output: a, b (11 rows) -select avg(a) from def group by a; +select avg(a) from xc_groupby_def group by a; avg ------------------------ @@ -297,7 +293,7 @@ select avg(a) from def group by a; 4.0000000000000000 (11 rows) -select avg(a) from def group by a; +select avg(a) from xc_groupby_def group by a; avg ------------------------ @@ -313,18 +309,18 @@ select avg(a) from def group by a; 4.0000000000000000 (11 rows) -explain verbose select avg(a) from def group by a; +explain verbose select avg(a) from xc_groupby_def group by a; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: pg_catalog.avg((avg(def.a))), def.a + Output: pg_catalog.avg((avg(xc_groupby_def.a))), xc_groupby_def.a -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(def.a)), def.a + Output: (avg(xc_groupby_def.a)), xc_groupby_def.a -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=4) - Output: avg(def.a), def.a + Output: avg(xc_groupby_def.a), xc_groupby_def.a (6 rows) -select avg(a) from def group by b; +select avg(a) from xc_groupby_def group by b; avg -------------------- 4.0000000000000000 @@ -333,18 +329,18 @@ select avg(a) from def group by b; 6.2000000000000000 (4 rows) -explain verbose select avg(a) from def group by b; +explain verbose select avg(a) from xc_groupby_def group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=33) - Output: pg_catalog.avg((avg(def.a))), def.b + HashAggregate (cost=1.02..1.03 rows=1 width=72) + Output: pg_catalog.avg((avg(xc_groupby_def.a))), xc_groupby_def.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(def.a)), def.b - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=33) - Output: avg(def.a), def.b + Output: (avg(xc_groupby_def.a)), xc_groupby_def.b + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=72) + Output: avg(xc_groupby_def.a), xc_groupby_def.b (6 rows) -select sum(a) from def group by b; +select sum(a) from xc_groupby_def group by b; sum ----- 8 @@ -353,18 +349,18 @@ select sum(a) from def group by b; 31 (4 rows) -explain verbose select sum(a) from def group by b; +explain verbose select sum(a) from xc_groupby_def group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=33) - Output: pg_catalog.sum((sum(def.a))), def.b + HashAggregate (cost=1.02..1.03 rows=1 width=72) + Output: pg_catalog.sum((sum(xc_groupby_def.a))), xc_groupby_def.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(def.a)), def.b - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=33) - Output: sum(def.a), def.b + Output: (sum(xc_groupby_def.a)), xc_groupby_def.b + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=72) + Output: sum(xc_groupby_def.a), xc_groupby_def.b (6 rows) -select count(*) from def group by b; +select count(*) from xc_groupby_def group by b; count ------- 3 @@ -373,18 +369,18 @@ select count(*) from def group by b; 5 (4 rows) -explain verbose select count(*) from def group by b; +explain verbose select count(*) from xc_groupby_def group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=29) - Output: pg_catalog.count(*), def.b + HashAggregate (cost=1.02..1.03 rows=1 width=68) + Output: pg_catalog.count(*), xc_groupby_def.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (count(*)), def.b - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=29) - Output: count(*), def.b + Output: (count(*)), xc_groupby_def.b + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=68) + Output: count(*), xc_groupby_def.b (6 rows) -select count(*) from def where a is not null group by a; +select count(*) from xc_groupby_def where a is not null group by a; count ------- 1 @@ -399,18 +395,18 @@ select count(*) from def where a is not null group by a; 1 (10 rows) -explain verbose select count(*) from def where a is not null group by a; +explain verbose select count(*) from xc_groupby_def where a is not null group by a; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: pg_catalog.count(*), def.a + Output: pg_catalog.count(*), xc_groupby_def.a -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (count(*)), def.a + Output: (count(*)), xc_groupby_def.a -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=4) - Output: count(*), def.a + Output: count(*), xc_groupby_def.a (6 rows) -select b from def group by b; +select b from xc_groupby_def group by b; b ------- @@ -419,18 +415,18 @@ select b from def group by b; Three (4 rows) -explain verbose select b from def group by b; +explain verbose select b from xc_groupby_def group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=29) - Output: def.b + HashAggregate (cost=1.02..1.03 rows=1 width=68) + Output: xc_groupby_def.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: def.b - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=29) - Output: def.b + Output: xc_groupby_def.b + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=68) + Output: xc_groupby_def.b (6 rows) -select b,count(b) from def group by b; +select b,count(b) from xc_groupby_def group by b; b | count -------+------- | 0 @@ -439,156 +435,156 @@ select b,count(b) from def group by b; Three | 5 (4 rows) -explain verbose select b,count(b) from def group by b; +explain verbose select b,count(b) from xc_groupby_def group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=29) - Output: def.b, count((count(def.b))) + HashAggregate (cost=1.02..1.03 rows=1 width=68) + Output: xc_groupby_def.b, count((count(xc_groupby_def.b))) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: def.b, (count(def.b)) - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=29) - Output: def.b, count(def.b) + Output: xc_groupby_def.b, (count(xc_groupby_def.b)) + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=68) + Output: xc_groupby_def.b, count(xc_groupby_def.b) (6 rows) -select count(*) from def where b is null group by b; +select count(*) from xc_groupby_def where b is null group by b; count ------- 3 (1 row) -explain verbose select count(*) from def where b is null group by b; +explain verbose select count(*) from xc_groupby_def where b is null group by b; QUERY PLAN ----------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.03 rows=1 width=29) - Output: pg_catalog.count(*), def.b + HashAggregate (cost=1.02..1.03 rows=1 width=68) + Output: pg_catalog.count(*), xc_groupby_def.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (count(*)), def.b - -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=29) - Output: count(*), def.b + Output: (count(*)), xc_groupby_def.b + -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=68) + Output: count(*), xc_groupby_def.b (6 rows) -create table g(a int, b float, c numeric); -insert into g values(1,2.1,3.2); -insert into g values(1,2.1,3.2); -insert into g values(2,2.3,5.2); -select sum(a) from g group by a; +create table xc_groupby_g(a int, b float, c numeric); +insert into xc_groupby_g values(1,2.1,3.2); +insert into xc_groupby_g values(1,2.1,3.2); +insert into xc_groupby_g values(2,2.3,5.2); +select sum(a) from xc_groupby_g group by a; sum ----- 2 2 (2 rows) -explain verbose select sum(a) from g group by a; +explain verbose select sum(a) from xc_groupby_g group by a; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: pg_catalog.sum((sum(g.a))), g.a + Output: pg_catalog.sum((sum(xc_groupby_g.a))), xc_groupby_g.a -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(g.a)), g.a + Output: (sum(xc_groupby_g.a)), xc_groupby_g.a -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=4) - Output: sum(g.a), g.a + Output: sum(xc_groupby_g.a), xc_groupby_g.a (6 rows) -select sum(b) from g group by b; +select sum(b) from xc_groupby_g group by b; sum ----- 2.3 4.2 (2 rows) -explain verbose select sum(b) from g group by b; +explain verbose select sum(b) from xc_groupby_g group by b; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: sum((sum(g.b))), g.b + Output: sum((sum(xc_groupby_g.b))), xc_groupby_g.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(g.b)), g.b + Output: (sum(xc_groupby_g.b)), xc_groupby_g.b -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=8) - Output: sum(g.b), g.b + Output: sum(xc_groupby_g.b), xc_groupby_g.b (6 rows) -select sum(c) from g group by b; +select sum(c) from xc_groupby_g group by b; sum ----- 5.2 6.4 (2 rows) -explain verbose select sum(c) from g group by b; +explain verbose select sum(c) from xc_groupby_g group by b; QUERY PLAN ----------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=40) - Output: sum((sum(g.c))), g.b + Output: sum((sum(xc_groupby_g.c))), xc_groupby_g.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(g.c)), g.b + Output: (sum(xc_groupby_g.c)), xc_groupby_g.b -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=40) - Output: sum(g.c), g.b + Output: sum(xc_groupby_g.c), xc_groupby_g.b (6 rows) -select avg(a) from g group by b; +select avg(a) from xc_groupby_g group by b; avg ------------------------ 2.0000000000000000 1.00000000000000000000 (2 rows) -explain verbose select avg(a) from g group by b; +explain verbose select avg(a) from xc_groupby_g group by b; QUERY PLAN ----------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=12) - Output: pg_catalog.avg((avg(g.a))), g.b + Output: pg_catalog.avg((avg(xc_groupby_g.a))), xc_groupby_g.b -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(g.a)), g.b + Output: (avg(xc_groupby_g.a)), xc_groupby_g.b -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=12) - Output: avg(g.a), g.b + Output: avg(xc_groupby_g.a), xc_groupby_g.b (6 rows) -select avg(b) from g group by c; +select avg(b) from xc_groupby_g group by c; avg ----- 2.3 2.1 (2 rows) -explain verbose select avg(b) from g group by c; +explain verbose select avg(b) from xc_groupby_g group by c; QUERY PLAN ----------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=40) - Output: pg_catalog.avg((avg(g.b))), g.c + Output: pg_catalog.avg((avg(xc_groupby_g.b))), xc_groupby_g.c -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(g.b)), g.c + Output: (avg(xc_groupby_g.b)), xc_groupby_g.c -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=40) - Output: avg(g.b), g.c + Output: avg(xc_groupby_g.b), xc_groupby_g.c (6 rows) -select avg(c) from g group by c; +select avg(c) from xc_groupby_g group by c; avg -------------------- 5.2000000000000000 3.2000000000000000 (2 rows) -explain verbose select avg(c) from g group by c; +explain verbose select avg(c) from xc_groupby_g group by c; QUERY PLAN ----------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=32) - Output: pg_catalog.avg((avg(g.c))), g.c + Output: pg_catalog.avg((avg(xc_groupby_g.c))), xc_groupby_g.c -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(g.c)), g.c + Output: (avg(xc_groupby_g.c)), xc_groupby_g.c -> Data Node Scan (Node Count [2]) (cost=0.00..1.01 rows=1000 width=32) - Output: avg(g.c), g.c + Output: avg(xc_groupby_g.c), xc_groupby_g.c (6 rows) -drop table def; -drop table g; +drop table xc_groupby_def; +drop table xc_groupby_g; -- Combination 2, enable_hashagg on and replicated tables. -- repeat the same tests for replicated tables -- create required tables and fill them with data -create table tab1 (val int, val2 int) distribute by replication; -create table tab2 (val int, val2 int) distribute by replication; -insert into tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 group by val2; +create table xc_groupby_tab1 (val int, val2 int) distribute by replication; +create table xc_groupby_tab2 (val int, val2 int) distribute by replication; +insert into xc_groupby_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); +insert into xc_groupby_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); +select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_groupby_tab1 group by val2; count | sum | avg | ?column? | val2 -------+-----+--------------------+------------------+------ 3 | 6 | 2.0000000000000000 | 2 | 1 @@ -596,10 +592,10 @@ select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 g 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 (3 rows) -explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from tab1 group by val2; +explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_groupby_tab1 group by val2; QUERY PLAN ------------------------------------------------------------------------------------------------------------- - HashAggregate (cost=1.03..1.06 rows=1 width=8) + HashAggregate (cost=1.03..1.05 rows=1 width=8) Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) Output: val, val2 @@ -608,7 +604,7 @@ explain verbose select count(*), sum(val), avg(val), sum(val)::float8/count(*), (6 rows) -- joins and group by -select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val*tab2.val)::float8/count(*), tab1.val2, tab2.val2 from tab1 full outer join tab2 on tab1.val2 = tab2.val2 group by tab1.val2, tab2.val2; +select count(*), sum(xc_groupby_tab1.val * xc_groupby_tab2.val), avg(xc_groupby_tab1.val*xc_groupby_tab2.val), sum(xc_groupby_tab1.val*xc_groupby_tab2.val)::float8/count(*), xc_groupby_tab1.val2, xc_groupby_tab2.val2 from xc_groupby_tab1 full outer join xc_groupby_tab2 on xc_groupby_tab1.val2 = xc_groupby_tab2.val2 group by xc_groupby_tab1.val2, xc_groupby_tab2.val2; count | sum | avg | ?column? | val2 | val2 -------+-----+---------------------+------------------+------+------ 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 @@ -617,53 +613,49 @@ select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val* 3 | | | | | 4 (4 rows) -explain verbose select count(*), sum(tab1.val * tab2.val), avg(tab1.val*tab2.val), sum(tab1.val*tab2.val)::float8/count(*), tab1.val2, tab2.val2 from tab1 full outer join tab2 on tab1.val2 = tab2.val2 group by tab1.val2, tab2.val2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate (cost=2.09..2.13 rows=1 width=16) - Output: count(*), sum((tab1.val * tab2.val)), avg((tab1.val * tab2.val)), ((sum((tab1.val * tab2.val)))::double precision / (count(*))::double precision), tab1.val2, tab2.val2 - -> Merge Full Join (cost=2.05..2.07 rows=1 width=16) - Output: tab1.val, tab1.val2, tab2.val, tab2.val2 - Merge Cond: (tab1.val2 = tab2.val2) - -> Sort (cost=1.02..1.03 rows=1 width=8) - Output: tab1.val, tab1.val2 - Sort Key: tab1.val2 +explain verbose select count(*), sum(xc_groupby_tab1.val * xc_groupby_tab2.val), avg(xc_groupby_tab1.val*xc_groupby_tab2.val), sum(xc_groupby_tab1.val*xc_groupby_tab2.val)::float8/count(*), xc_groupby_tab1.val2, xc_groupby_tab2.val2 from xc_groupby_tab1 full outer join xc_groupby_tab2 on xc_groupby_tab1.val2 = xc_groupby_tab2.val2 group by xc_groupby_tab1.val2, xc_groupby_tab2.val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + HashAggregate (cost=2.08..2.10 rows=1 width=16) + Output: count(*), sum((xc_groupby_tab1.val * xc_groupby_tab2.val)), avg((xc_groupby_tab1.val * xc_groupby_tab2.val)), ((sum((xc_groupby_tab1.val * xc_groupby_tab2.val)))::double precision / (count(*))::double precision), xc_groupby_tab1.val2, xc_groupby_tab2.val2 + -> Hash Full Join (cost=1.03..2.06 rows=1 width=16) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2, xc_groupby_tab2.val, xc_groupby_tab2.val2 + Hash Cond: (xc_groupby_tab1.val2 = xc_groupby_tab2.val2) + -> Materialize (cost=0.00..1.01 rows=1 width=8) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2 + -> Data Node Scan (Node Count [1]) on xc_groupby_tab1 (cost=0.00..1.01 rows=1000 width=8) + Output: xc_groupby_tab1.val, xc_groupby_tab1.val2 + -> Hash (cost=1.01..1.01 rows=1 width=8) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) - Output: tab1.val, tab1.val2 - -> Data Node Scan (Node Count [1]) on tab1 (cost=0.00..1.01 rows=1000 width=8) - Output: tab1.val, tab1.val2 - -> Sort (cost=1.02..1.03 rows=1 width=8) - Output: tab2.val, tab2.val2 - Sort Key: tab2.val2 - -> Materialize (cost=0.00..1.01 rows=1 width=8) - Output: tab2.val, tab2.val2 - -> Data Node Scan (Node Count [1]) on tab2 (cost=0.00..1.01 rows=1000 width=8) - Output: tab2.val, tab2.val2 -(19 rows) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 + -> Data Node Scan (Node Count [1]) on xc_groupby_tab2 (cost=0.00..1.01 rows=1000 width=8) + Output: xc_groupby_tab2.val, xc_groupby_tab2.val2 +(15 rows) -- aggregates over aggregates -select sum(y) from (select sum(val) y, val2%2 x from tab1 group by val2) q1 group by x; +select sum(y) from (select sum(val) y, val2%2 x from xc_groupby_tab1 group by val2) q1 group by x; sum ----- 8 17 (2 rows) -explain verbose select sum(y) from (select sum(val) y, val2%2 x from tab1 group by val2) q1 group by x; - QUERY PLAN ----------------------------------------------------------------------------------------- +explain verbose select sum(y) from (select sum(val) y, val2%2 x from xc_groupby_tab1 group by val2) q1 group by x; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.05..1.06 rows=1 width=12) - Output: sum((pg_catalog.sum((sum(tab1.val))))), ((tab1.val2 % 2)) + Output: sum((pg_catalog.sum((sum(xc_groupby_tab1.val))))), ((xc_groupby_tab1.val2 % 2)) -> HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: pg_catalog.sum((sum(tab1.val))), ((tab1.val2 % 2)), tab1.val2 + Output: pg_catalog.sum((sum(xc_groupby_tab1.val))), ((xc_groupby_tab1.val2 % 2)), xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(tab1.val)), ((tab1.val2 % 2)), tab1.val2 + Output: (sum(xc_groupby_tab1.val)), ((xc_groupby_tab1.val2 % 2)), xc_groupby_tab1.val2 -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=8) - Output: sum(tab1.val), (tab1.val2 % 2), tab1.val2 + Output: sum(xc_groupby_tab1.val), (xc_groupby_tab1.val2 % 2), xc_groupby_tab1.val2 (8 rows) -- group by without aggregate -select val2 from tab1 group by val2; +select val2 from xc_groupby_tab1 group by val2; val2 ------ 1 @@ -671,18 +663,18 @@ select val2 from tab1 group by val2; 3 (3 rows) -explain verbose select val2 from tab1 group by val2; +explain verbose select val2 from xc_groupby_tab1 group by val2; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=4) - Output: tab1.val2 + Output: xc_groupby_tab1.val2 (6 rows) -select val + val2 from tab1 group by val + val2; +select val + val2 from xc_groupby_tab1 group by val + val2; ?column? ---------- 4 @@ -693,18 +685,18 @@ select val + val2 from tab1 group by val + val2; 2 (6 rows) -explain verbose select val + val2 from tab1 group by val + val2; +explain verbose select val + val2 from xc_groupby_tab1 group by val + val2; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: ((tab1.val + tab1.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab1.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)) -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=8) - Output: (tab1.val + tab1.val2) + Output: (xc_groupby_tab1.val + xc_groupby_tab1.val2) (6 rows) -select val + val2, val, val2 from tab1 group by val, val2; +select val + val2, val, val2 from xc_groupby_tab1 group by val, val2; ?column? | val | val2 ----------+-----+------ 7 | 4 | 3 @@ -717,18 +709,18 @@ select val + val2, val, val2 from tab1 group by val, val2; 9 | 6 | 3 (8 rows) -explain verbose select val + val2, val, val2 from tab1 group by val, val2; - QUERY PLAN ----------------------------------------------------------------------------------- +explain verbose select val + val2, val, val2 from xc_groupby_tab1 group by val, val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=8) - Output: ((tab1.val + tab1.val2)), tab1.val, tab1.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)), xc_groupby_tab1.val, xc_groupby_tab1.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab1.val2)), tab1.val, tab1.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab1.val2)), xc_groupby_tab1.val, xc_groupby_tab1.val2 -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=8) - Output: (tab1.val + tab1.val2), tab1.val, tab1.val2 + Output: (xc_groupby_tab1.val + xc_groupby_tab1.val2), xc_groupby_tab1.val, xc_groupby_tab1.val2 (6 rows) -select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val, tab2.val2; +select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2; ?column? | val | val2 ----------+-----+------ 5 | 3 | 2 @@ -739,18 +731,18 @@ select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val 7 | 3 | 4 (6 rows) -explain verbose select tab1.val + tab2.val2, tab1.val, tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val, tab2.val2; - QUERY PLAN -------------------------------------------------------------------------------- +explain verbose select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------- HashAggregate (cost=0.00..0.01 rows=1 width=0) - Output: ((tab1.val + tab2.val2)), tab1.val, tab2.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)), xc_groupby_tab1.val, xc_groupby_tab2.val2 -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab2.val2)), tab1.val, tab2.val2 + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)), xc_groupby_tab1.val, xc_groupby_tab2.val2 -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1 width=4) - Output: (tab1.val + tab2.val2), tab1.val, tab2.val2 + Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2 (6 rows) -select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val + tab2.val2; +select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2; ?column? ---------- 6 @@ -759,19 +751,19 @@ select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by t 5 (4 rows) -explain verbose select tab1.val + tab2.val2 from tab1, tab2 where tab1.val = tab2.val group by tab1.val + tab2.val2; +explain verbose select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2; QUERY PLAN ------------------------------------------------------------------------------- HashAggregate (cost=0.00..0.01 rows=1 width=0) - Output: ((tab1.val + tab2.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: ((tab1.val + tab2.val2)) + Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2)) -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1 width=4) - Output: (tab1.val + tab2.val2) + Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2) (6 rows) -- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; +select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2; ?column? | val2 ---------------------+------ 11.0000000000000000 | 1 @@ -779,10 +771,10 @@ select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; 17.6666666666666667 | 3 (3 rows) -explain verbose select count(*) + sum(val) + avg(val), val2 from tab1 group by val2; +explain verbose select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2; QUERY PLAN ---------------------------------------------------------------------------------- - HashAggregate (cost=1.02..1.05 rows=1 width=8) + HashAggregate (cost=1.02..1.04 rows=1 width=8) Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 -> Materialize (cost=0.00..1.01 rows=1 width=8) Output: val, val2 @@ -791,7 +783,7 @@ explain verbose select count(*) + sum(val) + avg(val), val2 from tab1 group by v (6 rows) -- group by with expressions in group by clause -select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; +select sum(val), avg(val), 2 * val2 from xc_groupby_tab1 group by 2 * val2; sum | avg | ?column? -----+--------------------+---------- 11 | 3.6666666666666667 | 6 @@ -799,35 +791,35 @@ select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; 8 | 4.0000000000000000 | 4 (3 rows) -explain verbose select sum(val), avg(val), 2 * val2 from tab1 group by 2 * val2; - QUERY PLAN ------------------------------------------------------------------------------------------------ +explain verbose select sum(val), avg(val), 2 * val2 from xc_groupby_tab1 group by 2 * val2; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.04 rows=1 width=8) - Output: pg_catalog.sum((sum(tab1.val))), pg_catalog.avg((avg(tab1.val))), ((2 * tab1.val2)) + Output: pg_catalog.sum((sum(xc_groupby_tab1.val))), pg_catalog.avg((avg(xc_groupby_tab1.val))), ((2 * xc_groupby_tab1.val2)) -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (sum(tab1.val)), (avg(tab1.val)), ((2 * tab1.val2)) + Output: (sum(xc_groupby_tab1.val)), (avg(xc_groupby_tab1.val)), ((2 * xc_groupby_tab1.val2)) -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=8) - Output: sum(tab1.val), avg(tab1.val), (2 * tab1.val2) + Output: sum(xc_groupby_tab1.val), avg(xc_groupby_tab1.val), (2 * xc_groupby_tab1.val2) (6 rows) -drop table tab1; -drop table tab2; +drop table xc_groupby_tab1; +drop table xc_groupby_tab2; -- some tests involving nulls, characters, float type etc. -create table def(a int, b varchar(25)) distribute by replication; -insert into def VALUES (NULL, NULL); -insert into def VALUES (1, NULL); -insert into def VALUES (NULL, 'One'); -insert into def VALUES (2, 'Two'); -insert into def VALUES (2, 'Two'); -insert into def VALUES (3, 'Three'); -insert into def VALUES (4, 'Three'); -insert into def VALUES (5, 'Three'); -insert into def VALUES (6, 'Two'); -insert into def VALUES (7, NULL); -insert into def VALUES (8, 'Two'); -insert into def VALUES (9, 'Three'); -insert into def VALUES (10, 'Three'); -select a,count(a) from def group by a order by a; +create table xc_groupby_def(a int, b varchar(25)) distribute by replication; +insert into xc_groupby_def VALUES (NULL, NULL); +insert into xc_groupby_def VALUES (1, NULL); +insert into xc_groupby_def VALUES (NULL, 'One'); +insert into xc_groupby_def VALUES (2, 'Two'); +insert into xc_groupby_def VALUES (2, 'Two'); +insert into xc_groupby_def VALUES (3, 'Three'); +insert into xc_groupby_def VALUES (4, 'Three'); +insert into xc_groupby_def VALUES (5, 'Three'); +insert into xc_groupby_def VALUES (6, 'Two'); +insert into xc_groupby_def VALUES (7, NULL); +insert into xc_groupby_def VALUES (8, 'Two'); +insert into xc_groupby_def VALUES (9, 'Three'); +insert into xc_groupby_def VALUES (10, 'Three'); +select a,count(a) from xc_groupby_def group by a order by a; a | count ----+------- 1 | 1 @@ -843,14 +835,14 @@ select a,count(a) from def group by a order by a; | 0 (11 rows) -explain verbose select a,count(a) from def group by a order by a; +explain verbose select a,count(a) from xc_groupby_def group by a order by a; QUERY PLAN ---------------------------------------------------------------------------------------------- - GroupAggregate (cost=1.02..1.05 rows=1 width=4) + GroupAggregate (cost=1.02..1.04 rows=1 width=4) Output: a, count(a) -> Sort (cost=1.02..1.03 rows=1 width=4) Output: a - Sort Key: def.a + Sort Key: xc_groupby_def.a -> Result (cost=0.00..1.01 rows=1 width=4) Output: a -> Materialize (cost=0.00..1.01 rows=1 width=4) @@ -859,7 +851,7 @@ explain verbose select a,count(a) from def group by a order by a; Output: a, b (11 rows) -select avg(a) from def group by a; +select avg(a) from xc_groupby_def group by a; avg ------------------------ @@ -875,18 +867,18 @@ select avg(a) from def group by a; 4.0000000000000000 (11 rows) -explain verbose select avg(a) from def group by a; +explain verbose select avg(a) from xc_groupby_def group by a; QUERY PLAN ---------------------------------------------------------------------------------- HashAggregate (cost=1.02..1.03 rows=1 width=4) - Output: pg_catalog.avg((avg(def.a))), def.a + Output: pg_catalog.avg((avg(xc_groupby_def.a))), xc_groupby_def.a -> Materialize (cost=0.00..0.00 rows=0 width=0) - Output: (avg(def.a)), def.a + Output: (avg(xc_groupby_def.a)), xc_groupby_def.a -> Data Node Scan (Node Count [1]) (cost=0.00..1.01 rows=1000 width=4) - Output: avg(def.a), def.a + Output: avg(xc_groupby_def.a), xc_groupby_def.a (6 rows) -select avg(a) from def group by a; +select avg(a) from xc_groupby_def group by a; avg ------------------------ @@ -902,18 +894,18 @@ select avg(a) from def group by a; 4.0000000000000000 (11 rows) -explain verbose select avg(a) from def group by a; +explain verbose select avg(a) from xc_groupby_def group by a; ... [truncated message content] |