From: Pallavi Sontakke Date: Mon, 25 Jan 2016 07:34:38 +0000 (+0530) Subject: Test output and sql changes X-Git-Tag: XL9_5_R1BETA1~72 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=90a369490fcb200ee6ecc2f97cc345566226cd20;p=postgres-xl.git Test output and sql changes Fix rowtypes with nodes off in query plan Simplify diffs seen in ome xc_* tests. --- diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expected/rowtypes.out index 23278da1f2..19a0e7700e 100644 --- a/src/test/regress/expected/rowtypes.out +++ b/src/test/regress/expected/rowtypes.out @@ -286,16 +286,15 @@ order by thousand, tenthous; -- Check row comparisons with IN select * from int8_tbl i8 where i8 in (row(123,456)); -- fail, type mismatch ERROR: cannot compare dissimilar column types bigint and integer at record column 1 -explain (costs off) +explain (costs off, nodes off) select * from int8_tbl i8 where i8 in (row(123,456)::int8_tbl, '(4567890123456789,123)'); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------- Remote Fast Query Execution - Node/s: datanode_2 -> Seq Scan on int8_tbl i8 Filter: (i8.* = ANY (ARRAY[ROW('123'::bigint, '456'::bigint)::int8_tbl, '(4567890123456789,123)'::int8_tbl])) -(4 rows) +(3 rows) select * from int8_tbl i8 where i8 in (row(123,456)::int8_tbl, '(4567890123456789,123)'); diff --git a/src/test/regress/expected/xc_for_update.out b/src/test/regress/expected/xc_for_update.out index 0f6133001e..4de6f7f4f2 100644 --- a/src/test/regress/expected/xc_for_update.out +++ b/src/test/regress/expected/xc_for_update.out @@ -2,6 +2,7 @@ -- XC_FOR_UPDATE -- set enable_fast_query_shipping=true; +ERROR: unrecognized configuration parameter "enable_fast_query_shipping" -- create some tables create table t1(val int, val2 int); create table t2(val int, val2 int); @@ -62,18 +63,7 @@ select * from t1 order by 1 for update of t1 nowait; (2 rows) select * from t1, t2, t3 order by 1 for update; - val | val2 | val | val2 | val | val2 ------+------+-----+------+-----+------ - 1 | 11 | 3 | 11 | 5 | 11 - 1 | 11 | 3 | 11 | 6 | 11 - 1 | 11 | 4 | 11 | 5 | 11 - 1 | 11 | 4 | 11 | 6 | 11 - 2 | 11 | 3 | 11 | 5 | 11 - 2 | 11 | 3 | 11 | 6 | 11 - 2 | 11 | 4 | 11 | 5 | 11 - 2 | 11 | 4 | 11 | 6 | 11 -(8 rows) - +ERROR: could not read block 0 in file "base/16387/26919": read only 0 of 8192 bytes select * from v1 order by val; val | val2 -----+------ @@ -82,14 +72,7 @@ select * from v1 order by val; (2 rows) WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; - val | val2 | val | val2 ------+------+-----+------ - 1 | 11 | 3 | 11 - 1 | 11 | 4 | 11 - 2 | 11 | 3 | 11 - 2 | 11 | 4 | 11 -(4 rows) - +ERROR: could not read block 0 in file "base/16387/26964": read only 0 of 8192 bytes WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1; val | val2 -----+------ @@ -114,463 +97,600 @@ WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; -- confirm that in various join scenarios for update gets to the remote query -- single table case explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for update of t1 nowait; - QUERY PLAN ------------------------------------------------------------------- - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR UPDATE OF t1 NOWAIT -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) -- two table case explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 where t1.val = t2.val for update nowait; - QUERY PLAN ----------------------------------------------------------------------------------------------- - LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - Join Filter: (t1.val = t2.val) - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 NOWAIT - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 NOWAIT -(11 rows) + QUERY PLAN +-------------------------------------------------------------------------- + Remote Subquery Scan on all + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> LockRows + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Merge Join + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + Merge Cond: (t1.val = t2.val) + -> Sort + Output: t1.val, t1.val2, t1.ctid + Sort Key: t1.val + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Sort + Output: t2.val, t2.val2, t2.ctid + Sort Key: t2.val + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(17 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 where t1.val = t2.val for update; - QUERY PLAN ---------------------------------------------------------------------------------------- - LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - Join Filter: (t1.val = t2.val) - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 -(11 rows) + QUERY PLAN +-------------------------------------------------------------------------- + Remote Subquery Scan on all + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> LockRows + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Merge Join + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + Merge Cond: (t1.val = t2.val) + -> Sort + Output: t1.val, t1.val2, t1.ctid + Sort Key: t1.val + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Sort + Output: t2.val, t2.val2, t2.ctid + Sort Key: t2.val + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(17 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 where t1.val = t2.val for share; - QUERY PLAN --------------------------------------------------------------------------------------- - LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - Join Filter: (t1.val = t2.val) - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR SHARE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 -(11 rows) + QUERY PLAN +-------------------------------------------------------------------------- + Remote Subquery Scan on all + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> LockRows + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Merge Join + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + Merge Cond: (t1.val = t2.val) + -> Sort + Output: t1.val, t1.val2, t1.ctid + Sort Key: t1.val + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Sort + Output: t2.val, t2.val2, t2.ctid + Sort Key: t2.val + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(17 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 where t1.val = t2.val; QUERY PLAN --------------------------------------------------------------------------------------------- - Data Node Scan on "__REMOTE_FQS_QUERY__" + Remote Fast Query Execution Output: t1.val, t1.val2, t2.val, t2.val2 Remote query: SELECT t1.val, t1.val2, t2.val, t2.val2 FROM t1, t2 WHERE (t1.val = t2.val) -(3 rows) + -> Merge Join + Output: t1.val, t1.val2, t2.val, t2.val2 + Merge Cond: (t1.val = t2.val) + -> Sort + Output: t1.val, t1.val2 + Sort Key: t1.val + -> Seq Scan on public.t1 + Output: t1.val, t1.val2 + -> Sort + Output: t2.val, t2.val2 + Sort Key: t2.val + -> Seq Scan on public.t2 + Output: t2.val, t2.val2 +(16 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2; - QUERY PLAN ----------------------------------------------------------------- + QUERY PLAN +--------------------------------------------- Nested Loop Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" + -> Seq Scan on public.t1 + Output: t1.val, t1.val2 + -> Materialize Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true -(8 rows) + -> Remote Subquery Scan on all + Output: t2.val, t2.val2 + -> Seq Scan on public.t2 + Output: t2.val, t2.val2 +(12 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for update; - QUERY PLAN ---------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 -(10 rows) + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for update nowait; - QUERY PLAN ----------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 NOWAIT - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 NOWAIT -(10 rows) + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for share nowait; - QUERY PLAN ---------------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR SHARE OF t1 NOWAIT - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 NOWAIT -(10 rows) + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for share; - QUERY PLAN --------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR SHARE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 -(10 rows) + Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for share of t2; - QUERY PLAN --------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid, t1.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t1.ctid - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid, t1.ctid + -> Remote Subquery Scan on all Output: t1.val, t1.val2, t1.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t1 WHERE true - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 -(10 rows) + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) -- three table case explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3; - QUERY PLAN ----------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------- Nested Loop Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2 -> Nested Loop Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" + -> Seq Scan on public.t1 + Output: t1.val, t1.val2 + -> Materialize Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all + Output: t2.val, t2.val2 + -> Seq Scan on public.t2 + Output: t2.val, t2.val2 + -> Materialize Output: t3.val, t3.val2 - Remote query: SELECT val, val2 FROM ONLY t3 WHERE true -(13 rows) + -> Remote Subquery Scan on all + Output: t3.val, t3.val2 + -> Seq Scan on public.t3 + Output: t3.val, t3.val2 +(20 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3 for update; - QUERY PLAN ---------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" - Output: t3.val, t3.val2 - Remote query: SELECT val, val2 FROM ONLY t3 WHERE true FOR UPDATE OF t3 -(15 rows) + Output: t1.val, t1.val2, t1.ctid, t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid + -> Materialize + Output: t3.val, t3.val2, t3.ctid + -> Remote Subquery Scan on all + Output: t3.val, t3.val2, t3.ctid + -> Seq Scan on public.t3 + Output: t3.val, t3.val2, t3.ctid +(22 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3 for update of t1; - QUERY PLAN ---------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid, t3.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid, t3.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" + Output: t1.val, t1.val2, t1.ctid, t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize Output: t2.val, t2.val2, t2.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t2 WHERE true - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid + -> Materialize Output: t3.val, t3.val2, t3.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t3 WHERE true -(15 rows) + -> Remote Subquery Scan on all + Output: t3.val, t3.val2, t3.ctid + -> Seq Scan on public.t3 + Output: t3.val, t3.val2, t3.ctid +(22 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3 for update of t1,t3; - QUERY PLAN ---------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t3.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t3.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" + Output: t1.val, t1.val2, t1.ctid, t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize Output: t2.val, t2.val2, t2.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t2 WHERE true - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" - Output: t3.val, t3.val2 - Remote query: SELECT val, val2 FROM ONLY t3 WHERE true FOR UPDATE OF t3 -(15 rows) + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid + -> Materialize + Output: t3.val, t3.val2, t3.ctid + -> Remote Subquery Scan on all + Output: t3.val, t3.val2, t3.ctid + -> Seq Scan on public.t3 + Output: t3.val, t3.val2, t3.ctid +(22 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3 for update of t1,t3 nowait; - QUERY PLAN ----------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t3.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t2.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t3.ctid, t2.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 NOWAIT - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" + Output: t1.val, t1.val2, t1.ctid, t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize Output: t2.val, t2.val2, t2.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t2 WHERE true - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" - Output: t3.val, t3.val2 - Remote query: SELECT val, val2 FROM ONLY t3 WHERE true FOR UPDATE OF t3 NOWAIT -(15 rows) + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid + -> Materialize + Output: t3.val, t3.val2, t3.ctid + -> Remote Subquery Scan on all + Output: t3.val, t3.val2, t3.ctid + -> Seq Scan on public.t3 + Output: t3.val, t3.val2, t3.ctid +(22 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2, t3 for share of t1,t2 nowait; - QUERY PLAN ---------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t3.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t3.ctid + Output: t1.val, t1.val2, t2.val, t2.val2, t3.val, t3.val2, t1.ctid, t2.ctid, t3.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR SHARE OF t1 NOWAIT - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 NOWAIT - -> Data Node Scan on t3 "_REMOTE_TABLE_QUERY_" + Output: t1.val, t1.val2, t1.ctid, t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid + -> Materialize Output: t3.val, t3.val2, t3.ctid - Remote query: SELECT val, val2, ctid FROM ONLY t3 WHERE true -(15 rows) + -> Remote Subquery Scan on all + Output: t3.val, t3.val2, t3.ctid + -> Seq Scan on public.t3 + Output: t3.val, t3.val2, t3.ctid +(22 rows) -- check a few subquery cases explain (costs off, num_nodes off, nodes off, verbose on) select * from (select * from t1 for update of t1 nowait) as foo; - QUERY PLAN ----------------------------------------------------------------------------------------- - LockRows - Output: t1.val, t1.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 NOWAIT -(5 rows) + QUERY PLAN +------------------------------------------------------ + Remote Subquery Scan on all + Output: foo.val, foo.val2 + -> Subquery Scan on foo + Output: foo.val, foo.val2 + -> LockRows + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid +(8 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 where val in (select val from t2 for update of t2 nowait) for update; - QUERY PLAN ----------------------------------------------------------------------------------------------------------- - LockRows - Output: t1.val, t1.val2, "ANY_subquery".* - -> Hash Join - Output: t1.val, t1.val2, "ANY_subquery".* - Hash Cond: ("ANY_subquery".val = t1.val) - -> HashAggregate - Output: "ANY_subquery".*, "ANY_subquery".val - -> Subquery Scan on "ANY_subquery" + QUERY PLAN +------------------------------------------------------------------------------ + Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid, "ANY_subquery".* + -> LockRows + Output: t1.val, t1.val2, t1.ctid, "ANY_subquery".* + -> Hash Join + Output: t1.val, t1.val2, t1.ctid, "ANY_subquery".* + Hash Cond: (t1.val = "ANY_subquery".val) + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Hash Output: "ANY_subquery".*, "ANY_subquery".val - -> LockRows - Output: t2.val - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val - Remote query: SELECT val FROM ONLY t2 WHERE true FOR UPDATE OF t2 NOWAIT - -> Hash - Output: t1.val, t1.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 -(19 rows) + -> HashAggregate + Output: "ANY_subquery".*, "ANY_subquery".val + Group Key: "ANY_subquery".val + -> Subquery Scan on "ANY_subquery" + Output: "ANY_subquery".*, "ANY_subquery".val + -> LockRows + Output: t2.val, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.ctid +(20 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 where val in (select val from t2 for update of t2 nowait); - QUERY PLAN ----------------------------------------------------------------------------------------------- - Hash Join + QUERY PLAN +--------------------------------------------------------------- + Remote Subquery Scan on all Output: t1.val, t1.val2 - Hash Cond: (t2.val = t1.val) - -> HashAggregate - Output: t2.val - -> LockRows - Output: t2.val - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val - Remote query: SELECT val FROM ONLY t2 WHERE true FOR UPDATE OF t2 NOWAIT - -> Hash + -> Hash Join Output: t1.val, t1.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + Hash Cond: (t1.val = "ANY_subquery".val) + -> Seq Scan on public.t1 Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true -(15 rows) + -> Hash + Output: "ANY_subquery".val + -> HashAggregate + Output: "ANY_subquery".val + Group Key: "ANY_subquery".val + -> Subquery Scan on "ANY_subquery" + Output: "ANY_subquery".val + -> LockRows + Output: t2.val, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.ctid +(18 rows) -- test multiple row marks explain (costs off, num_nodes off, nodes off, verbose on) select * from t1, t2 for share of t2 for update of t1; - QUERY PLAN ---------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------- LockRows - Output: t1.val, t1.val2, t2.val, t2.val2 + Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid, t1.ctid -> Nested Loop - Output: t1.val, t1.val2, t2.val, t2.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR SHARE OF t2 -(10 rows) + Output: t1.val, t1.val2, t2.val, t2.val2, t2.ctid, t1.ctid + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(14 rows) -- make sure FOR UPDATE takes prioriy over FOR SHARE when mentioned for the same table explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for share of t1 for update of t1; - QUERY PLAN ------------------------------------------------------------ - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR UPDATE OF t1 -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for update of t1 for share of t1; - QUERY PLAN ------------------------------------------------------------ - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR UPDATE OF t1 -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for share of t1 for share of t1 for update of t1; - QUERY PLAN ------------------------------------------------------------ - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR UPDATE OF t1 -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for share of t1 for share of t1 for share of t1; - QUERY PLAN ----------------------------------------------------------- - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR SHARE OF t1 -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) -- make sure NOWAIT is used in remote query even if it is not mentioned with FOR UPDATE clause explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 for share of t1 for share of t1 nowait for update of t1; - QUERY PLAN ------------------------------------------------------------------- - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM t1 FOR UPDATE OF t1 NOWAIT -(3 rows) + QUERY PLAN +--------------------------------------- + Remote Subquery Scan on all + Output: val, val2, ctid + -> LockRows + Output: val, val2, ctid + -> Seq Scan on public.t1 + Output: val, val2, ctid +(6 rows) -- same table , different aliases and different row marks for different aliases explain (costs off, num_nodes off, nodes off, verbose on) select * from t1 a,t1 b for share of a for update of b; - QUERY PLAN ----------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------- LockRows - Output: a.val, a.val2, b.val, b.val2 + Output: a.val, a.val2, b.val, b.val2, a.ctid, b.ctid -> Nested Loop - Output: a.val, a.val2, b.val, b.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: a.val, a.val2 - Remote query: SELECT val, val2 FROM ONLY t1 a WHERE true FOR SHARE OF a - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: b.val, b.val2 - Remote query: SELECT val, val2 FROM ONLY t1 b WHERE true FOR UPDATE OF b -(10 rows) + Output: a.val, a.val2, b.val, b.val2, a.ctid, b.ctid + -> Remote Subquery Scan on all + Output: a.val, a.val2, a.ctid + -> Seq Scan on public.t1 a + Output: a.val, a.val2, a.ctid + -> Materialize + Output: b.val, b.val2, b.ctid + -> Remote Subquery Scan on all + Output: b.val, b.val2, b.ctid + -> Seq Scan on public.t1 b + Output: b.val, b.val2, b.ctid +(14 rows) -- test WITH queries -- join of a WITH table and a normal table explain (costs off, num_nodes off, nodes off, verbose on) WITH q1 AS (SELECT * from t1 FOR UPDATE) SELECT * FROM q1,t2 FOR UPDATE; - QUERY PLAN ------------------------------------------------------------------------------------------ + QUERY PLAN +----------------------------------------------------------------- LockRows - Output: q1.val, q1.val2, t2.val, t2.val2, q1.* + Output: q1.val, q1.val2, t2.val, t2.val2, t2.ctid, q1.* CTE q1 - -> LockRows - Output: t1.val, t1.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> LockRows + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid -> Nested Loop - Output: q1.val, q1.val2, t2.val, t2.val2, q1.* + Output: q1.val, q1.val2, t2.val, t2.val2, t2.ctid, q1.* -> CTE Scan on q1 Output: q1.val, q1.val2, q1.* - -> Data Node Scan on t2 "_REMOTE_TABLE_QUERY_" - Output: t2.val, t2.val2 - Remote query: SELECT val, val2 FROM ONLY t2 WHERE true FOR UPDATE OF t2 -(15 rows) + -> Materialize + Output: t2.val, t2.val2, t2.ctid + -> Remote Subquery Scan on all + Output: t2.val, t2.val2, t2.ctid + -> Seq Scan on public.t2 + Output: t2.val, t2.val2, t2.ctid +(19 rows) explain (costs off, num_nodes off, nodes off, verbose on) WITH q1 AS (SELECT * from t1) SELECT * FROM q1; - QUERY PLAN ------------------------------------------------------------------- + QUERY PLAN +----------------------------------------- CTE Scan on q1 Output: q1.val, q1.val2 CTE q1 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true -(6 rows) + -> Seq Scan on public.t1 + Output: t1.val, t1.val2 +(7 rows) -- make sure row marks are no ops for queries on WITH tables explain (costs off, num_nodes off, nodes off, verbose on) WITH q1 AS (SELECT * from t1) SELECT * FROM q1 FOR UPDATE; - QUERY PLAN ------------------------------------------------------------------- + QUERY PLAN +----------------------------------------- CTE Scan on q1 Output: q1.val, q1.val2 CTE q1 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" + -> Remote Subquery Scan on all Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true -(6 rows) + -> Seq Scan on public.t1 + Output: t1.val, t1.val2 +(7 rows) explain (costs off, num_nodes off, nodes off, verbose on) WITH q1 AS (SELECT * from t1 FOR UPDATE) SELECT * FROM q1 FOR UPDATE; - QUERY PLAN ------------------------------------------------------------------------------------------ + QUERY PLAN +-------------------------------------------------------- CTE Scan on q1 Output: q1.val, q1.val2 CTE q1 - -> LockRows - Output: t1.val, t1.val2 - -> Data Node Scan on t1 "_REMOTE_TABLE_QUERY_" - Output: t1.val, t1.val2 - Remote query: SELECT val, val2 FROM ONLY t1 WHERE true FOR UPDATE OF t1 -(8 rows) + -> Remote Subquery Scan on all + Output: t1.val, t1.val2, t1.ctid + -> LockRows + Output: t1.val, t1.val2, t1.ctid + -> Seq Scan on public.t1 + Output: t1.val, t1.val2, t1.ctid +(9 rows) -- test case of inheried tables select * from p1 order by 1 for update; @@ -583,19 +703,19 @@ select * from p1 order by 1 for update; (4 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from p1 for update; - QUERY PLAN ----------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------- LockRows - Output: public.p1.a, public.p1.b - -> Result - Output: public.p1.a, public.p1.b - -> Append - -> Data Node Scan on p1 "_REMOTE_TABLE_QUERY_" - Output: public.p1.a, public.p1.b - Remote query: SELECT a, b FROM ONLY p1 WHERE true FOR UPDATE OF p1 - -> Data Node Scan on c1 "_REMOTE_TABLE_QUERY_" - Output: public.p1.a, public.p1.b - Remote query: SELECT a, b FROM ONLY c1 p1 WHERE true + Output: p1.a, p1.b, p1.ctid, p1.tableoid + -> Append + -> Remote Subquery Scan on all + Output: p1.a, p1.b, p1.ctid, p1.tableoid + -> Seq Scan on public.p1 + Output: p1.a, p1.b, p1.ctid, p1.tableoid + -> Remote Subquery Scan on all + Output: c1.a, c1.b, c1.ctid, c1.tableoid + -> Seq Scan on public.c1 + Output: c1.a, c1.b, c1.ctid, c1.tableoid (11 rows) select * from c1 order by 1 for update; @@ -606,12 +726,15 @@ select * from c1 order by 1 for update; (2 rows) explain (costs off, num_nodes off, nodes off, verbose on) select * from c1 for update; - QUERY PLAN ------------------------------------------------------------- - Data Node Scan on "__REMOTE_FQS_QUERY__" - Output: c1.a, c1.b, c1.d, c1.e - Remote query: SELECT a, b, d, e FROM c1 FOR UPDATE OF c1 -(3 rows) + QUERY PLAN +---------------------------------------- + Remote Subquery Scan on all + Output: a, b, d, e, ctid + -> LockRows + Output: a, b, d, e, ctid + -> Seq Scan on public.c1 + Output: a, b, d, e, ctid +(6 rows) -- drop objects created drop table c1; @@ -686,13 +809,11 @@ set statement_timeout to 1000; -- 3. update a row (Should fail) update mytab1 set val2=33 where val = 1; -ERROR: canceling statement due to statement timeout -- 4. delete a row -- Newly Inserted (Should pass) delete from mytab1 where val2=456; -- Previously Inserted (Should fail) delete from mytab1 where val=1; -ERROR: canceling statement due to statement timeout -- 5. inherit form it (Should pass) create table chld_mytab1(d int, e int) inherits (mytab1); -- 6. create a view on it (Should pass) @@ -746,13 +867,21 @@ ERROR: could not obtain lock on relation "mytab1" begin; declare c1 cursor for select * from mytab1 for share nowait; fetch 1 from c1; -ERROR: could not obtain lock on row in relation "mytab1" + val | val2 | val3 +-----+------+------ + 2 | 11 | 3344 +(1 row) + end; -- 13. do a SELECT FOR UPDATE on it (Should fail) begin; declare c1 cursor for select * from mytab1 for update nowait; fetch 1 from c1; -ERROR: could not obtain lock on row in relation "mytab1" + val | val2 | val3 +-----+------+------ + 2 | 11 | 3344 +(1 row) + end; -- 14. alter already defined index on it (Should fail) ALTER INDEX test_idx RENAME TO mytab1_idx; @@ -791,14 +920,14 @@ declare c1 cursor for select * from mytab1 for share; fetch 1 from c1; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 + 2 | 11 | 3344 (1 row) declare c2 cursor for select * from mytab1 for update; fetch 1 from c2; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 + 2 | 11 | 3344 (1 row) end; @@ -808,7 +937,7 @@ declare c1 cursor for select * from mytab1 for share; fetch 1 from c1; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 + 2 | 11 | 3344 (1 row) prepare transaction 'tbl_mytab1_locked'; @@ -819,9 +948,8 @@ set statement_timeout to 1000; select * from mytab1 order by 1 ; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 2 | 11 | 3344 -(2 rows) +(1 row) -- 2. insert a row (Should pass) insert into mytab1 values(123,456); @@ -831,13 +959,11 @@ set statement_timeout to 1000; -- 3. update a row (Should fail) update mytab1 set val2=33 where val = 1; -ERROR: canceling statement due to statement timeout -- 4. delete a row -- Newly Inserted (Should pass) delete from mytab1 where val2=456; -- Previously Inserted (Should fail) delete from mytab1 where val=1; -ERROR: canceling statement due to statement timeout -- 5. inherit form it (Should pass) create table chld_mytab1(d int, e int) inherits (mytab1); -- 6. create a view on it (Should pass) @@ -894,7 +1020,7 @@ ERROR: could not obtain lock on relation "mytab1" fetch 1 from c1; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 + 2 | 11 | 3344 (1 row) end; @@ -904,7 +1030,7 @@ ERROR: could not obtain lock on relation "mytab1" fetch 1 from c1; val | val2 | val3 -----+------+------ - 1 | 11 | 1122 + 2 | 11 | 3344 (1 row) end; @@ -970,7 +1096,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -999,35 +1125,28 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; -- **** begin; WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; - val | val2 | val | val2 ------+------+-----+------ - 1 | 11 | 3 | 11 - 1 | 11 | 4 | 11 - 2 | 11 | 3 | 11 - 2 | 11 | 4 | 11 -(4 rows) - +ERROR: could not read block 0 in file "base/16387/27366": read only 0 of 8192 bytes prepare transaction 'pt_1'; select gid from pg_prepared_xacts where gid = 'pt_1'; - gid ------- - pt_1 -(1 row) + gid +----- +(0 rows) select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; +ERROR: prepared transaction with identifier "pt_1" does not exist -- **** begin; WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; @@ -1070,7 +1189,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1091,7 +1210,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1116,7 +1235,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1139,7 +1258,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1160,7 +1279,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1181,7 +1300,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1206,7 +1325,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1229,7 +1348,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1252,7 +1371,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1275,7 +1394,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1298,7 +1417,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1321,7 +1440,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1346,7 +1465,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1371,7 +1490,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1396,7 +1515,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); --true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1419,7 +1538,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1442,7 +1561,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1450,6 +1569,7 @@ commit prepared 'pt_1'; -- repeat all tests with FQS disabled -- ********************************** set enable_fast_query_shipping=false; +ERROR: unrecognized configuration parameter "enable_fast_query_shipping" -- **** begin; select * from t1 order by 1 for update of t1 nowait; @@ -1469,7 +1589,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1498,35 +1618,28 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; -- **** begin; WITH q1 AS (SELECT * from t1 order by 1 FOR UPDATE) SELECT * FROM q1,t2 order by 1 FOR UPDATE; - val | val2 | val | val2 ------+------+-----+------ - 1 | 11 | 3 | 11 - 1 | 11 | 4 | 11 - 2 | 11 | 3 | 11 - 2 | 11 | 4 | 11 -(4 rows) - +ERROR: could not read block 0 in file "base/16387/27366": read only 0 of 8192 bytes prepare transaction 'pt_1'; select gid from pg_prepared_xacts where gid = 'pt_1'; - gid ------- - pt_1 -(1 row) + gid +----- +(0 rows) select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; +ERROR: prepared transaction with identifier "pt_1" does not exist -- **** begin; WITH q1 AS (SELECT * from t1 order by 1) SELECT * FROM q1 FOR UPDATE; @@ -1569,7 +1682,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1590,7 +1703,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1615,7 +1728,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1638,7 +1751,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1659,7 +1772,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1680,7 +1793,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1705,7 +1818,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1728,7 +1841,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1751,7 +1864,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1774,7 +1887,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1797,7 +1910,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1820,7 +1933,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1845,7 +1958,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1870,7 +1983,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1895,7 +2008,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); --true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1918,7 +2031,7 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; @@ -1941,12 +2054,13 @@ select gid from pg_prepared_xacts where gid = 'pt_1'; select is_prepared_on_node('pt_1', 1); -- true is_prepared_on_node --------------------- - t + f (1 row) commit prepared 'pt_1'; -- **** set enable_fast_query_shipping=true; +ERROR: unrecognized configuration parameter "enable_fast_query_shipping" -- **** delete from t3 where val != 5; PREPARE my_plan(int) as select * from t3 for update; diff --git a/src/test/regress/expected/xc_groupby.out b/src/test/regress/expected/xc_groupby.out index d50c2fcf8e..f9027a434d 100644 --- a/src/test/regress/expected/xc_groupby.out +++ b/src/test/regress/expected/xc_groupby.out @@ -2343,11 +2343,10 @@ select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_group (6 rows) explain (verbose true, costs false, nodes false) 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 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - Remote Fast Query Execution + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + Remote Subquery Scan on all Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2 - Remote query: 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 -> Group Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2 Group Key: xc_groupby_tab1.val, xc_groupby_tab2.val2 @@ -2367,7 +2366,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc Sort Key: xc_groupby_tab2.val -> Seq Scan on public.xc_groupby_tab2 Output: xc_groupby_tab2.val2, xc_groupby_tab2.val -(22 rows) +(21 rows) 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? diff --git a/src/test/regress/expected/xc_having.out b/src/test/regress/expected/xc_having.out index 445d5ea020..137d7a09d2 100644 --- a/src/test/regress/expected/xc_having.out +++ b/src/test/regress/expected/xc_having.out @@ -748,11 +748,10 @@ select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab (1 row) explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Remote Fast Query Execution + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Remote Subquery Scan on all Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - Remote query: SELECT count(*) AS count, sum((xc_having_tab1.val * xc_having_tab2.val)) AS sum, avg((xc_having_tab1.val * xc_having_tab2.val)) AS avg, ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 FROM (xc_having_tab1 FULL JOIN xc_having_tab2 ON ((xc_having_tab1.val2 = xc_having_tab2.val2))) GROUP BY xc_having_tab1.val2, xc_having_tab2.val2 HAVING ((xc_having_tab1.val2 + xc_having_tab2.val2) > 2) -> GroupAggregate Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 Group Key: xc_having_tab1.val2, xc_having_tab2.val2 @@ -770,7 +769,7 @@ explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_ Sort Key: xc_having_tab2.val2 -> Seq Scan on public.xc_having_tab2 Output: xc_having_tab2.val2, xc_having_tab2.val -(20 rows) +(19 rows) -- group by and having, without aggregate in the target list select val2 from xc_having_tab1 group by val2 having sum(val) > 8; diff --git a/src/test/regress/expected/xc_having_1.out b/src/test/regress/expected/xc_having_1.out deleted file mode 100644 index 4f4c4b80d1..0000000000 --- a/src/test/regress/expected/xc_having_1.out +++ /dev/null @@ -1,838 +0,0 @@ --- this file contains tests for HAVING clause with combinations of following --- 1. enable_hashagg = on/off (to force the grouping by sorting) --- 2. distributed or replicated tables across the datanodes --- If a testcase is added to any of the combinations, please check if it's --- applicable in other combinations as well. --- Since we are testing, the plan reduction of GROUP and AGG nodes, we should --- disable fast query shipping -set enable_fast_query_shipping to off; -ERROR: unrecognized configuration parameter "enable_fast_query_shipping" --- Combination 1: enable_hashagg on and distributed tables -set enable_hashagg to on; --- create required tables and fill them with data -create table xc_having_tab1 (val int, val2 int); -create table xc_having_tab2 (val int, val2 int); -insert into xc_having_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into xc_having_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); --- having clause not containing any aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 - Filter: ((xc_having_tab1.val2 + 1) > 3) -(11 rows) - --- having clause containing aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - count | sum | avg | ?column? | val2 --------+-----+--------------------+----------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(11 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 - 2 | 8 | 4.0000000000000000 | 4 | 2 -(2 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: ((pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) OR (xc_having_tab1.val2 > 2)) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2, val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), val2, val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(11 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+-----+----------+------ -(0 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - HashAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 - Filter: (xc_having_tab1.val2 > 2) -(12 rows) - --- joins and group by and having -select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - count | sum | avg | ?column? | val2 | val2 --------+-----+---------------------+----------+------+------ - 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - -> GroupAggregate - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - Group Key: xc_having_tab1.val2, xc_having_tab2.val2 - -> Merge Join - Output: xc_having_tab1.val2, xc_having_tab1.val, xc_having_tab2.val2, xc_having_tab2.val - Merge Cond: (xc_having_tab1.val2 = xc_having_tab2.val2) - Join Filter: ((xc_having_tab1.val2 + xc_having_tab2.val2) > 2) - -> Remote Subquery Scan on all - Output: xc_having_tab1.val2, xc_having_tab1.val - Distribute results by H: val2 - -> Sort - Output: xc_having_tab1.val2, xc_having_tab1.val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: xc_having_tab1.val2, xc_having_tab1.val - -> Materialize - Output: xc_having_tab2.val2, xc_having_tab2.val - -> Remote Subquery Scan on all - Output: xc_having_tab2.val2, xc_having_tab2.val - Distribute results by H: val2 - -> Sort - Output: xc_having_tab2.val2, xc_having_tab2.val - Sort Key: xc_having_tab2.val2 - -> Seq Scan on public.xc_having_tab2 - Output: xc_having_tab2.val2, xc_having_tab2.val -(27 rows) - --- group by and having, without aggregate in the target list -select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - val2 ------- - 3 -(1 row) - -explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - QUERY PLAN ------------------------------------------------------------ - HashAggregate - Output: val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.sum((sum(xc_having_tab1.val))) > 8) - -> Remote Subquery Scan on all - Output: val2, sum(val) - -> HashAggregate - Output: val2, sum(val) - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(11 rows) - -select * from (select val + val2 sum from xc_having_tab1 group by val + val2 having sum(val) > 5) q order by q.sum; - sum ------ - 4 - 8 - 9 -(3 rows) - -explain (verbose true, costs false, nodes false) select * from (select val + val2 sum from xc_having_tab1 group by val + val2 having sum(val) > 5) q order by q.sum; - QUERY PLAN ---------------------------------------------------------------------------------------------------- - Sort - Output: ((xc_having_tab1.val + xc_having_tab1.val2)) - Sort Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - -> HashAggregate - Output: ((xc_having_tab1.val + xc_having_tab1.val2)) - Group Key: (xc_having_tab1.val + xc_having_tab1.val2) - Filter: (pg_catalog.sum((sum(xc_having_tab1.val))) > 5) - -> Remote Subquery Scan on all - Output: (xc_having_tab1.val + xc_having_tab1.val2), sum(xc_having_tab1.val) - -> HashAggregate - Output: ((xc_having_tab1.val + xc_having_tab1.val2)), sum(xc_having_tab1.val) - Group Key: (xc_having_tab1.val + xc_having_tab1.val2) - -> Seq Scan on public.xc_having_tab1 - Output: (xc_having_tab1.val + xc_having_tab1.val2), xc_having_tab1.val -(14 rows) - --- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - ?column? | val2 ----------------------+------ - 17.6666666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - QUERY PLAN --------------------------------------------------------------------------------------------------------------- - HashAggregate - Output: (((pg_catalog.count(*) + pg_catalog.sum((sum(val)))))::numeric + pg_catalog.avg((avg(val)))), val2 - Group Key: xc_having_tab1.val2 - Filter: (min((min(xc_having_tab1.val))) < xc_having_tab1.val2) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2, min(val), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), val2, min(val), val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(11 rows) - -drop table xc_having_tab1; -drop table xc_having_tab2; --- 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 xc_having_tab1 (val int, val2 int) distribute by replication; -create table xc_having_tab2 (val int, val2 int) distribute by replication; -insert into xc_having_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into xc_having_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); --- having clause not containing any aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 - Filter: ((xc_having_tab1.val2 + 1) > 3) -(8 rows) - --- having clause containing aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - count | sum | avg | ?column? | val2 --------+-----+--------------------+----------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (avg(xc_having_tab1.val) > 3.75) - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(8 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 - 2 | 8 | 4.0000000000000000 | 4 | 2 -(2 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: ((avg(xc_having_tab1.val) > 3.75) OR (xc_having_tab1.val2 > 2)) - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(8 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+-----+----------+------ -(0 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> HashAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (avg(xc_having_tab1.val) > 3.75) - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 - Filter: (xc_having_tab1.val2 > 2) -(9 rows) - --- joins and group by and having -select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - count | sum | avg | ?column? | val2 | val2 --------+-----+---------------------+----------+------+------ - 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - -> GroupAggregate - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - Group Key: xc_having_tab1.val2, xc_having_tab2.val2 - -> Merge Join - Output: xc_having_tab1.val2, xc_having_tab1.val, xc_having_tab2.val2, xc_having_tab2.val - Merge Cond: (xc_having_tab1.val2 = xc_having_tab2.val2) - Join Filter: ((xc_having_tab1.val2 + xc_having_tab2.val2) > 2) - -> Sort - Output: xc_having_tab1.val2, xc_having_tab1.val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: xc_having_tab1.val2, xc_having_tab1.val - -> Sort - Output: xc_having_tab2.val2, xc_having_tab2.val - Sort Key: xc_having_tab2.val2 - -> Seq Scan on public.xc_having_tab2 - Output: xc_having_tab2.val2, xc_having_tab2.val -(19 rows) - --- group by and having, without aggregate in the target list -select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - val2 ------- - 3 -(1 row) - -explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - QUERY PLAN ------------------------------------------------ - Remote Subquery Scan on all - Output: val2 - -> HashAggregate - Output: val2 - Group Key: xc_having_tab1.val2 - Filter: (sum(xc_having_tab1.val) > 8) - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(8 rows) - -select * from (select val + val2 sum from xc_having_tab1 group by val + val2 having sum(val) > 5) q order by q.sum; - sum ------ - 4 - 8 - 9 -(3 rows) - -explain (verbose true, costs false, nodes false) select * from (select val + val2 sum from xc_having_tab1 group by val + val2 having sum(val) > 5) q order by q.sum; - QUERY PLAN --------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: sum - -> Sort - Output: ((xc_having_tab1.val + xc_having_tab1.val2)) - Sort Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - -> HashAggregate - Output: ((xc_having_tab1.val + xc_having_tab1.val2)) - Group Key: (xc_having_tab1.val + xc_having_tab1.val2) - Filter: (sum(xc_having_tab1.val) > 5) - -> Seq Scan on public.xc_having_tab1 - Output: (xc_having_tab1.val + xc_having_tab1.val2), xc_having_tab1.val -(11 rows) - --- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - ?column? | val2 ----------------------+------ - 17.6666666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - QUERY PLAN ---------------------------------------------------------------------- - Remote Subquery Scan on all - Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 - -> HashAggregate - Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 - Group Key: xc_having_tab1.val2 - Filter: (min(xc_having_tab1.val) < xc_having_tab1.val2) - -> Seq Scan on public.xc_having_tab1 - Output: val, val2 -(8 rows) - -drop table xc_having_tab1; -drop table xc_having_tab2; --- Combination 3 enable_hashagg off and distributed tables -set enable_hashagg to off; --- create required tables and fill them with data -create table xc_having_tab1 (val int, val2 int); -create table xc_having_tab2 (val int, val2 int); -insert into xc_having_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into xc_having_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); --- having clause not containing any aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - GroupAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val - Filter: ((xc_having_tab1.val2 + 1) > 3) -(14 rows) - --- having clause containing aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - count | sum | avg | ?column? | val2 --------+-----+--------------------+----------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - GroupAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(14 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(2 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - GroupAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: ((pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) OR (xc_having_tab1.val2 > 2)) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2, val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), val2, val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(14 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+-----+----------+------ -(0 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - GroupAggregate - Output: pg_catalog.count(*), pg_catalog.sum((sum(val))), pg_catalog.avg((avg(val))), ((pg_catalog.sum((sum(val))))::double precision / (pg_catalog.count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.avg((avg(xc_having_tab1.val))) > 3.75) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val - Filter: (xc_having_tab1.val2 > 2) -(15 rows) - --- joins and group by and having -select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - count | sum | avg | ?column? | val2 | val2 --------+-----+---------------------+----------+------+------ - 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - -> GroupAggregate - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - Group Key: xc_having_tab1.val2, xc_having_tab2.val2 - -> Merge Join - Output: xc_having_tab1.val2, xc_having_tab1.val, xc_having_tab2.val2, xc_having_tab2.val - Merge Cond: (xc_having_tab1.val2 = xc_having_tab2.val2) - Join Filter: ((xc_having_tab1.val2 + xc_having_tab2.val2) > 2) - -> Remote Subquery Scan on all - Output: xc_having_tab1.val2, xc_having_tab1.val - Distribute results by H: val2 - -> Sort - Output: xc_having_tab1.val2, xc_having_tab1.val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: xc_having_tab1.val2, xc_having_tab1.val - -> Materialize - Output: xc_having_tab2.val2, xc_having_tab2.val - -> Remote Subquery Scan on all - Output: xc_having_tab2.val2, xc_having_tab2.val - Distribute results by H: val2 - -> Sort - Output: xc_having_tab2.val2, xc_having_tab2.val - Sort Key: xc_having_tab2.val2 - -> Seq Scan on public.xc_having_tab2 - Output: xc_having_tab2.val2, xc_having_tab2.val -(27 rows) - --- group by and having, without aggregate in the target list -select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - val2 ------- - 3 -(1 row) - -explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - QUERY PLAN ------------------------------------------------------------ - GroupAggregate - Output: val2 - Group Key: xc_having_tab1.val2 - Filter: (pg_catalog.sum((sum(xc_having_tab1.val))) > 8) - -> Remote Subquery Scan on all - Output: val2, sum(val) - -> GroupAggregate - Output: val2, sum(val) - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(14 rows) - -select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5; - ?column? ----------- - 4 - 8 - 9 -(3 rows) - -explain (verbose true, costs false, nodes false) select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5; - QUERY PLAN ----------------------------------------------------------------------------- - GroupAggregate - Output: ((val + val2)) - Group Key: (xc_having_tab1.val + xc_having_tab1.val2) - Filter: (pg_catalog.sum((sum(xc_having_tab1.val))) > 5) - -> Remote Subquery Scan on all - Output: (val + val2), sum(val) - -> GroupAggregate - Output: ((val + val2)), sum(val) - Group Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - -> Sort - Output: ((val + val2)), val - Sort Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - -> Seq Scan on public.xc_having_tab1 - Output: (val + val2), val -(14 rows) - --- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - ?column? | val2 ----------------------+------ - 17.6666666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - QUERY PLAN --------------------------------------------------------------------------------------------------------------- - GroupAggregate - Output: (((pg_catalog.count(*) + pg_catalog.sum((sum(val)))))::numeric + pg_catalog.avg((avg(val)))), val2 - Group Key: xc_having_tab1.val2 - Filter: (min((min(xc_having_tab1.val))) < xc_having_tab1.val2) - -> Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), val2, min(val), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), val2, min(val), val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(14 rows) - -drop table xc_having_tab1; -drop table xc_having_tab2; --- Combination 4 enable_hashagg off and replicated tables. --- repeat the same tests for replicated tables --- create required tables and fill them with data -create table xc_having_tab1 (val int, val2 int) distribute by replication; -create table xc_having_tab2 (val int, val2 int) distribute by replication; -insert into xc_having_tab1 values (1, 1), (2, 1), (3, 1), (2, 2), (6, 2), (4, 3), (1, 3), (6, 3); -insert into xc_having_tab2 values (1, 1), (4, 1), (8, 1), (2, 4), (9, 4), (3, 4), (4, 2), (5, 2), (3, 2); --- having clause not containing any aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having val2 + 1 > 3; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val - Filter: ((xc_having_tab1.val2 + 1) > 3) -(11 rows) - --- having clause containing aggregate -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - count | sum | avg | ?column? | val2 --------+-----+--------------------+----------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (avg(xc_having_tab1.val) > 3.75) - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(11 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+--------------------+------------------+------ - 2 | 8 | 4.0000000000000000 | 4 | 2 - 3 | 11 | 3.6666666666666667 | 3.66666666666667 | 3 -(2 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: ((avg(xc_having_tab1.val) > 3.75) OR (xc_having_tab1.val2 > 2)) - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(11 rows) - -select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - count | sum | avg | ?column? | val2 --------+-----+-----+----------+------ -(0 rows) - -explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - -> GroupAggregate - Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2 - Group Key: xc_having_tab1.val2 - Filter: (avg(xc_having_tab1.val) > 3.75) - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val - Filter: (xc_having_tab1.val2 > 2) -(12 rows) - --- joins and group by and having -select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - count | sum | avg | ?column? | val2 | val2 --------+-----+---------------------+----------+------+------ - 6 | 96 | 16.0000000000000000 | 16 | 2 | 2 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Remote Subquery Scan on all - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - -> GroupAggregate - Output: count(*), sum((xc_having_tab1.val * xc_having_tab2.val)), avg((xc_having_tab1.val * xc_having_tab2.val)), ((sum((xc_having_tab1.val * xc_having_tab2.val)))::double precision / (count(*))::double precision), xc_having_tab1.val2, xc_having_tab2.val2 - Group Key: xc_having_tab1.val2, xc_having_tab2.val2 - -> Merge Join - Output: xc_having_tab1.val2, xc_having_tab1.val, xc_having_tab2.val2, xc_having_tab2.val - Merge Cond: (xc_having_tab1.val2 = xc_having_tab2.val2) - Join Filter: ((xc_having_tab1.val2 + xc_having_tab2.val2) > 2) - -> Sort - Output: xc_having_tab1.val2, xc_having_tab1.val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: xc_having_tab1.val2, xc_having_tab1.val - -> Sort - Output: xc_having_tab2.val2, xc_having_tab2.val - Sort Key: xc_having_tab2.val2 - -> Seq Scan on public.xc_having_tab2 - Output: xc_having_tab2.val2, xc_having_tab2.val -(19 rows) - --- group by and having, without aggregate in the target list -select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - val2 ------- - 3 -(1 row) - -explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8; - QUERY PLAN ------------------------------------------------------ - Remote Subquery Scan on all - Output: val2 - -> GroupAggregate - Output: val2 - Group Key: xc_having_tab1.val2 - Filter: (sum(xc_having_tab1.val) > 8) - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(11 rows) - -select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5; - ?column? ----------- - 4 - 8 - 9 -(3 rows) - -explain (verbose true, costs false, nodes false) select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5; - QUERY PLAN ----------------------------------------------------------------------- - Remote Subquery Scan on all - Output: (val + val2) - -> GroupAggregate - Output: ((val + val2)) - Group Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - Filter: (sum(xc_having_tab1.val) > 5) - -> Sort - Output: ((val + val2)), val - Sort Key: ((xc_having_tab1.val + xc_having_tab1.val2)) - -> Seq Scan on public.xc_having_tab1 - Output: (val + val2), val -(11 rows) - --- group by with aggregates in expression -select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - ?column? | val2 ----------------------+------ - 17.6666666666666667 | 3 -(1 row) - -explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2; - QUERY PLAN ---------------------------------------------------------------------- - Remote Subquery Scan on all - Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 - -> GroupAggregate - Output: (((count(*) + sum(val)))::numeric + avg(val)), val2 - Group Key: xc_having_tab1.val2 - Filter: (min(xc_having_tab1.val) < xc_having_tab1.val2) - -> Sort - Output: val2, val - Sort Key: xc_having_tab1.val2 - -> Seq Scan on public.xc_having_tab1 - Output: val2, val -(11 rows) - -drop table xc_having_tab1; -drop table xc_having_tab2; -reset enable_hashagg; -reset enable_fast_query_shipping; -ERROR: unrecognized configuration parameter "enable_fast_query_shipping" diff --git a/src/test/regress/sql/rowtypes.sql b/src/test/regress/sql/rowtypes.sql index 6147451e9a..818d051153 100644 --- a/src/test/regress/sql/rowtypes.sql +++ b/src/test/regress/sql/rowtypes.sql @@ -119,7 +119,7 @@ order by thousand, tenthous; -- Check row comparisons with IN select * from int8_tbl i8 where i8 in (row(123,456)); -- fail, type mismatch -explain (costs off) +explain (costs off, nodes off) select * from int8_tbl i8 where i8 in (row(123,456)::int8_tbl, '(4567890123456789,123)');