-- 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);
(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
-----+------
(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
-----+------
-- 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;
(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;
(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;
-- 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)
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;
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;
fetch 1 from c1;
val | val2 | val3
-----+------+------
- 1 | 11 | 1122
+ 2 | 11 | 3344
(1 row)
prepare transaction 'tbl_mytab1_locked';
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);
-- 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)
fetch 1 from c1;
val | val2 | val3
-----+------+------
- 1 | 11 | 1122
+ 2 | 11 | 3344
(1 row)
end;
fetch 1 from c1;
val | val2 | val3
-----+------+------
- 1 | 11 | 1122
+ 2 | 11 | 3344
(1 row)
end;
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared '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;
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); --true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
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;
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared '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;
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); --true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared 'pt_1';
select is_prepared_on_node('pt_1', 1); -- true
is_prepared_on_node
---------------------
- t
+ f
(1 row)
commit prepared '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;
+++ /dev/null
--- 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"