mirror of https://github.com/citusdata/citus.git
Merge pull request #1817 from citusdata/regression_parallelization
Regression parallelization - Part 1pull/1795/head
commit
4f3f30f939
|
@ -3,8 +3,8 @@
|
|||
--
|
||||
-- Test checks whether constraints of distributed tables can be adjusted using
|
||||
-- the ALTER TABLE ... ADD CONSTRAINT ... command.
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1450000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 1450000;
|
||||
SET citus.next_shard_id TO 1450000;
|
||||
SET citus.next_placement_id TO 1450000;
|
||||
-- Check "PRIMARY KEY CONSTRAINT"
|
||||
CREATE TABLE products (
|
||||
product_no integer,
|
||||
|
@ -487,6 +487,8 @@ SELECT "Constraint", "Definition" FROM table_checks WHERE relid='public.products
|
|||
(0 rows)
|
||||
|
||||
\c - - - :master_port
|
||||
SET citus.next_shard_id TO 1450038;
|
||||
SET citus.next_placement_id TO 1450038;
|
||||
DROP TABLE products;
|
||||
SET citus.shard_count to 2;
|
||||
-- Test if the ALTER TABLE %s ADD %s PRIMARY KEY %s works
|
||||
|
|
|
@ -452,10 +452,10 @@ Aggregate
|
|||
Sort Key: ((users.composite_id).tenant_id), ((users.composite_id).user_id)
|
||||
-> Hash Join
|
||||
Hash Cond: (users.composite_id = events.composite_id)
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: ((event_type)::text = ANY ('{click,submit,pay}'::text[]))
|
||||
-- Union and left join subquery pushdown
|
||||
EXPLAIN (COSTS OFF)
|
||||
|
@ -543,24 +543,24 @@ HashAggregate
|
|||
-> Append
|
||||
-> Hash Join
|
||||
Hash Cond: (users.composite_id = events.composite_id)
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: ((event_type)::text = 'click'::text)
|
||||
-> Hash Join
|
||||
Hash Cond: (users_1.composite_id = events_1.composite_id)
|
||||
-> Seq Scan on users_1400029 users_1
|
||||
-> Seq Scan on users_1400033 users_1
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events_1
|
||||
-> Seq Scan on events_1400029 events_1
|
||||
Filter: ((event_type)::text = 'submit'::text)
|
||||
-> Hash
|
||||
-> Subquery Scan on subquery_2
|
||||
-> Unique
|
||||
-> Sort
|
||||
Sort Key: ((events_2.composite_id).tenant_id), ((events_2.composite_id).user_id)
|
||||
-> Seq Scan on events_1400025 events_2
|
||||
-> Seq Scan on events_1400029 events_2
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type) AND ((event_type)::text = 'pay'::text))
|
||||
-- Union, left join and having subquery pushdown
|
||||
EXPLAIN (COSTS OFF)
|
||||
|
@ -706,12 +706,12 @@ Limit
|
|||
-> Limit
|
||||
-> Sort
|
||||
Sort Key: users.lastseen DESC
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Limit
|
||||
-> Sort
|
||||
Sort Key: events.event_time DESC
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: (composite_id = users.composite_id)
|
||||
-- Test all tasks output
|
||||
SET citus.explain_all_tasks TO on;
|
||||
|
|
|
@ -452,10 +452,10 @@ Aggregate
|
|||
Sort Key: ((users.composite_id).tenant_id), ((users.composite_id).user_id)
|
||||
-> Hash Join
|
||||
Hash Cond: (users.composite_id = events.composite_id)
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: ((event_type)::text = ANY ('{click,submit,pay}'::text[]))
|
||||
-- Union and left join subquery pushdown
|
||||
EXPLAIN (COSTS OFF)
|
||||
|
@ -543,24 +543,24 @@ HashAggregate
|
|||
-> Append
|
||||
-> Hash Join
|
||||
Hash Cond: (users.composite_id = events.composite_id)
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: ((event_type)::text = 'click'::text)
|
||||
-> Hash Join
|
||||
Hash Cond: (users_1.composite_id = events_1.composite_id)
|
||||
-> Seq Scan on users_1400029 users_1
|
||||
-> Seq Scan on users_1400033 users_1
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Hash
|
||||
-> Seq Scan on events_1400025 events_1
|
||||
-> Seq Scan on events_1400029 events_1
|
||||
Filter: ((event_type)::text = 'submit'::text)
|
||||
-> Hash
|
||||
-> Subquery Scan on subquery_2
|
||||
-> Unique
|
||||
-> Sort
|
||||
Sort Key: ((events_2.composite_id).tenant_id), ((events_2.composite_id).user_id)
|
||||
-> Seq Scan on events_1400025 events_2
|
||||
-> Seq Scan on events_1400029 events_2
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type) AND ((event_type)::text = 'pay'::text))
|
||||
-- Union, left join and having subquery pushdown
|
||||
EXPLAIN (COSTS OFF)
|
||||
|
@ -706,12 +706,12 @@ Limit
|
|||
-> Limit
|
||||
-> Sort
|
||||
Sort Key: users.lastseen DESC
|
||||
-> Seq Scan on users_1400029 users
|
||||
-> Seq Scan on users_1400033 users
|
||||
Filter: ((composite_id >= '(1,-9223372036854775808)'::user_composite_type) AND (composite_id <= '(1,9223372036854775807)'::user_composite_type))
|
||||
-> Limit
|
||||
-> Sort
|
||||
Sort Key: events.event_time DESC
|
||||
-> Seq Scan on events_1400025 events
|
||||
-> Seq Scan on events_1400029 events
|
||||
Filter: (composite_id = users.composite_id)
|
||||
-- Test all tasks output
|
||||
SET citus.explain_all_tasks TO on;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
-- ===================================================================
|
||||
-- test insert select functionality for window functions
|
||||
-- ===================================================================
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -14,15 +13,15 @@ FROM
|
|||
WINDOW my_win AS (PARTITION BY user_id ORDER BY time DESC)
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
10001 | 101 | 49.5810418958104190
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- the same test with different syntax
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -33,15 +32,15 @@ FROM
|
|||
events_table
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
10001 | 101 | 49.5810418958104190
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- similar test with lag
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg, value_3_agg)
|
||||
SELECT
|
||||
user_id, time, lag_event_type, row_no
|
||||
FROM
|
||||
|
@ -52,15 +51,15 @@ FROM
|
|||
events_table WINDOW my_win AS (PARTITION BY user_id ORDER BY time DESC)
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
10001 | 101 | 49.5810418958104190
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- simple window function, partitioned and grouped by on the distribution key
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT
|
||||
user_id, rnk, tme
|
||||
FROM
|
||||
|
@ -74,15 +73,15 @@ FROM
|
|||
WINDOW my_win AS (PARTITION BY user_id ORDER BY avg(event_type) DESC)
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
1188 | 101 | 49.7895622895622896
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- top level query has a group by on the result of the window function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
min(user_id), min(time), lag_event_type
|
||||
FROM
|
||||
|
@ -95,15 +94,15 @@ FROM
|
|||
GROUP BY
|
||||
lag_event_type;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+--------------------
|
||||
1002 | 50 | 9.7844311377245509
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- window functions should work along with joins as well
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -116,15 +115,15 @@ SELECT * FROM
|
|||
WINDOW w1 AS (PARTITION BY users_table.user_id, events_table.event_type ORDER BY events_table.time)
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
195 | 91 | 51.0205128205128205
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- two window functions in a single subquery should work fine as well
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -138,15 +137,15 @@ SELECT * FROM
|
|||
w2 AS (PARTITION BY users_table.user_id, (events_table.value_2 % 25) ORDER BY events_table.time)
|
||||
) as foo;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
202 | 91 | 50.2970297029702970
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- window functions should be fine within subquery joins
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg, value_3_agg)
|
||||
SELECT sub_1.user_id, max(lag_1), max(rank_1), max(rank_2) FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -175,15 +174,15 @@ JOIN
|
|||
GROUP BY
|
||||
sub_1.user_id;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
91 | 91 | 50.2637362637362637
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- GROUP BYs and PARTITION BYs should work fine together
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
avg(user_id), max(time), my_rank
|
||||
FROM
|
||||
|
@ -201,15 +200,15 @@ WHERE
|
|||
GROUP BY
|
||||
my_rank;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
7 | 6 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- aggregates in the PARTITION BY is also allows
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
avg(user_id), max(time), my_rank
|
||||
FROM
|
||||
|
@ -227,16 +226,16 @@ WHERE
|
|||
GROUP BY
|
||||
my_rank;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
8 | 7 | 48.8750000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- GROUP BY should not necessarly be inclusive of partitioning
|
||||
-- but this query doesn't make much sense
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT
|
||||
avg(user_id), my_rank
|
||||
FROM
|
||||
|
@ -252,15 +251,15 @@ FROM
|
|||
GROUP BY
|
||||
my_rank;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
1 | 1 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Group by has more columns than partition by which uses coordinator insert ... select
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, SUM(value_2) OVER (PARTITION BY user_id)
|
||||
|
@ -274,14 +273,14 @@ ORDER BY
|
|||
LIMIT
|
||||
10;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
10 | 10 | 49.1000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT user_id, max(sum) FROM (
|
||||
SELECT
|
||||
user_id, SUM(value_2) OVER (PARTITION BY user_id, value_1)
|
||||
|
@ -292,15 +291,15 @@ SELECT user_id, max(sum) FROM (
|
|||
) a
|
||||
GROUP BY user_id;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
101 | 101 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Subquery in where with window function
|
||||
INSERT INTO agg_results(user_id)
|
||||
INSERT INTO agg_results_window(user_id)
|
||||
SELECT
|
||||
user_id
|
||||
FROM
|
||||
|
@ -318,17 +317,17 @@ WHERE
|
|||
GROUP BY
|
||||
user_id;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
4 | 4 | 35.2500000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Partition by with aggregate functions. This query does not make much sense since the
|
||||
-- result of aggregate function will be the same for every row in a partition and it is
|
||||
-- not going to affect the group that the count function will work on.
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, COUNT(*) OVER (PARTITION BY user_id, MIN(value_2))
|
||||
|
@ -338,15 +337,15 @@ SELECT * FROM (
|
|||
1
|
||||
) a;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
101 | 101 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Some more nested queries
|
||||
INSERT INTO agg_results(user_id, value_2_agg, value_3_agg, value_4_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg, value_3_agg, value_4_agg)
|
||||
SELECT
|
||||
user_id, rank, SUM(ABS(value_2 - value_3)) AS difference, COUNT(*) AS distinct_users
|
||||
FROM (
|
||||
|
@ -361,14 +360,14 @@ FROM (
|
|||
GROUP BY
|
||||
user_id, rank;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
9501 | 101 | 49.8461214608988528
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT DISTINCT
|
||||
f3.user_id, ABS(f2.sum - f3.sum)
|
||||
|
@ -392,15 +391,15 @@ WHERE
|
|||
f3.user_id=f2.user_id
|
||||
) a;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
101 | 101 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- test with reference table partitioned on columns from both
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
|
@ -410,15 +409,15 @@ FROM
|
|||
users_table, users_ref_test_table
|
||||
) a;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
101 | 101 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Window functions with HAVING clause
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, rank() OVER (PARTITION BY user_id ORDER BY value_1)
|
||||
|
@ -428,15 +427,15 @@ SELECT * FROM (
|
|||
user_id, value_1 HAVING count(*) > 1
|
||||
) a;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
437 | 100 | 49.9496567505720824
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Window functions with HAVING clause which uses coordinator insert ... select
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, rank() OVER (PARTITION BY user_id ORDER BY value_1)
|
||||
|
@ -450,13 +449,13 @@ ORDER BY
|
|||
LIMIT
|
||||
10;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
10 | 5 | 32.4000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Window function in View works
|
||||
CREATE VIEW view_with_window_func AS
|
||||
SELECT
|
||||
|
@ -466,20 +465,20 @@ FROM
|
|||
GROUP BY
|
||||
user_id, value_1
|
||||
HAVING count(*) > 1;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
view_with_window_func;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
437 | 100 | 49.9496567505720824
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- Window function in View works and the query uses coordinator insert ... select
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
view_with_window_func
|
||||
|
@ -487,14 +486,14 @@ LIMIT
|
|||
10;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot run avg(user_id)
|
||||
SELECT count(*) FROM agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
count
|
||||
-------
|
||||
10
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT
|
||||
user_id, max(avg)
|
||||
FROM
|
||||
|
@ -517,14 +516,14 @@ LIMIT
|
|||
5;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot test avg or distinct count
|
||||
SELECT count(*) FROM agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
count
|
||||
-------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT
|
||||
user_id, max(avg)
|
||||
FROM
|
||||
|
@ -544,14 +543,14 @@ FROM
|
|||
GROUP BY
|
||||
user_id;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
94 | 94 | 50.4787234042553191
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
@ -589,14 +588,14 @@ LIMIT
|
|||
5;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot test avg or distinct count
|
||||
SELECT count(*) FROM agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
count
|
||||
-------
|
||||
5
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
TRUNCATE agg_results_window;
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
@ -631,15 +630,15 @@ FROM (
|
|||
)
|
||||
) AS ftop;
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
count | count | avg
|
||||
-------+-------+---------------------
|
||||
101 | 101 | 50.0000000000000000
|
||||
(1 row)
|
||||
|
||||
TRUNCATE agg_results;
|
||||
TRUNCATE agg_results_window;
|
||||
-- lets have some queries that Citus shouldn't push down
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -658,7 +657,7 @@ ERROR: cannot push down this subquery
|
|||
DETAIL: Window functions with PARTITION BY list missing distribution column is currently unsupported
|
||||
-- user needs to supply partition by which should
|
||||
-- include the distribution key
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -677,7 +676,7 @@ ERROR: cannot push down this subquery
|
|||
DETAIL: Window functions without PARTITION BY on distribution column is currently unsupported
|
||||
-- user needs to supply partition by which should
|
||||
-- include the distribution key
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -695,7 +694,7 @@ LIMIT
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions without PARTITION BY on distribution column is currently unsupported
|
||||
-- w2 should not be pushed down
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -713,7 +712,7 @@ LIMIT
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions with PARTITION BY list missing distribution column is currently unsupported
|
||||
-- GROUP BY includes the partition key, but not the WINDOW function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, my_rank
|
||||
FROM
|
||||
|
@ -731,7 +730,7 @@ WHERE
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions without PARTITION BY on distribution column is currently unsupported
|
||||
-- GROUP BY includes the partition key, but not the WINDOW function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, my_rank
|
||||
FROM
|
||||
|
@ -749,7 +748,7 @@ WHERE
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions with PARTITION BY list missing distribution column is currently unsupported
|
||||
-- w2 should not be allowed
|
||||
INSERT INTO agg_results (user_id, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_2_agg, value_3_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -765,7 +764,7 @@ SELECT * FROM
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions without PARTITION BY on distribution column is currently unsupported
|
||||
-- unsupported window function with an override
|
||||
INSERT INTO agg_results(user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, agg_time, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, date_trunc('day', time) as time, sum(rank) OVER w2
|
||||
|
@ -783,7 +782,7 @@ SELECT * FROM (
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions with PARTITION BY list missing distribution column is currently unsupported
|
||||
-- Subquery in where with unsupported window function
|
||||
INSERT INTO agg_results(user_id)
|
||||
INSERT INTO agg_results_window(user_id)
|
||||
SELECT
|
||||
user_id
|
||||
FROM
|
||||
|
@ -803,7 +802,7 @@ GROUP BY
|
|||
ERROR: cannot push down this subquery
|
||||
DETAIL: Window functions without PARTITION BY on distribution column is currently unsupported
|
||||
-- Aggregate function on distribution column should error out
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, COUNT(*) OVER (PARTITION BY sum(user_id), MIN(value_2))
|
||||
|
@ -816,7 +815,7 @@ ERROR: cannot push down this subquery
|
|||
DETAIL: Window functions with PARTITION BY list missing distribution column is currently unsupported
|
||||
-- UNION with only one subquery which has a partition on non-distribution column should
|
||||
-- error out
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
|
|
@ -28,6 +28,10 @@ SELECT create_distributed_table('agg_results_third', 'user_id');
|
|||
CREATE TABLE agg_results_fourth (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp);
|
||||
SELECT create_distributed_table('agg_results_fourth', 'user_id');
|
||||
|
||||
-- same as agg_results_second
|
||||
CREATE TABLE agg_results_window (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp);
|
||||
SELECT create_distributed_table('agg_results_window', 'user_id');
|
||||
|
||||
CREATE TABLE users_ref_test_table(id int, it_name varchar(25), k_no int);
|
||||
SELECT create_reference_table('users_ref_test_table');
|
||||
INSERT INTO users_ref_test_table VALUES(1,'User_1',45);
|
||||
|
|
|
@ -30,35 +30,24 @@ test: multi_read_from_secondaries
|
|||
# uploading data to it.
|
||||
# ----------
|
||||
test: multi_create_table
|
||||
test: multi_create_table_constraints
|
||||
test: multi_master_protocol
|
||||
test: multi_load_data
|
||||
test: multi_create_table_constraints multi_master_protocol multi_load_data multi_behavioral_analytics_create_table
|
||||
test: multi_behavioral_analytics_basics multi_behavioral_analytics_single_shard_queries multi_insert_select_non_pushable_queries multi_insert_select multi_insert_select_window multi_shard_update_delete
|
||||
|
||||
test: multi_behavioral_analytics_create_table
|
||||
test: multi_behavioral_analytics_basics multi_behavioral_analytics_single_shard_queries multi_insert_select_non_pushable_queries
|
||||
test: multi_insert_select multi_insert_select_window
|
||||
test: multi_shard_update_delete
|
||||
|
||||
# ---
|
||||
# ----------
|
||||
# Tests for partitioning support
|
||||
# ---
|
||||
test: multi_partitioning_utils
|
||||
test: multi_partitioning
|
||||
# ----------
|
||||
test: multi_partitioning_utils multi_partitioning
|
||||
|
||||
# ----------
|
||||
# Miscellaneous tests to check our query planning behavior
|
||||
# ----------
|
||||
test: multi_deparse_shard_query multi_distributed_transaction_id
|
||||
test: multi_basic_queries multi_complex_expressions
|
||||
test: multi_explain
|
||||
test: multi_subquery multi_subquery_complex_queries multi_subquery_behavioral_analytics
|
||||
test: multi_subquery_complex_reference_clause multi_subquery_window_functions
|
||||
test: multi_basic_queries multi_complex_expressions multi_subquery multi_subquery_complex_queries multi_subquery_behavioral_analytics
|
||||
test: multi_subquery_complex_reference_clause multi_subquery_window_functions multi_view multi_sql_function multi_prepare_sql
|
||||
test: multi_subquery_in_where_reference_clause
|
||||
test: multi_subquery_union multi_subquery_in_where_clause multi_subquery_misc
|
||||
test: multi_reference_table
|
||||
test: multi_outer_join_reference
|
||||
test: multi_single_relation_subquery
|
||||
test: multi_agg_distinct multi_agg_approximate_distinct multi_limit_clause_approximate
|
||||
test: multi_agg_distinct multi_agg_approximate_distinct multi_limit_clause_approximate multi_reference_table multi_outer_join_reference multi_single_relation_subquery multi_prepare_plsql
|
||||
test: multi_average_expression multi_working_columns multi_having_pushdown
|
||||
test: multi_array_agg multi_limit_clause
|
||||
test: multi_agg_type_conversion multi_count_type_conversion
|
||||
|
@ -70,10 +59,6 @@ test: multi_task_assignment_policy multi_cross_shard
|
|||
test: multi_utility_statements
|
||||
test: multi_dropped_column_aliases
|
||||
test: multi_binary_master_copy_format
|
||||
test: multi_prepare_sql
|
||||
test: multi_prepare_plsql
|
||||
test: multi_sql_function
|
||||
test: multi_view
|
||||
|
||||
# ----------
|
||||
# Parallel TPC-H tests to check our distributed execution behavior
|
||||
|
@ -109,7 +94,7 @@ test: multi_shard_modify
|
|||
# ----------
|
||||
# Tests around DDL statements run on distributed tables
|
||||
# ----------
|
||||
test: multi_index_statements
|
||||
test: multi_index_statements
|
||||
test: multi_alter_table_statements
|
||||
test: multi_alter_table_add_constraints
|
||||
|
||||
|
|
|
@ -51,6 +51,14 @@ SELECT create_distributed_table('agg_results_fourth', 'user_id');
|
|||
|
||||
(1 row)
|
||||
|
||||
-- same as agg_results_second
|
||||
CREATE TABLE agg_results_window (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp);
|
||||
SELECT create_distributed_table('agg_results_window', 'user_id');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE users_ref_test_table(id int, it_name varchar(25), k_no int);
|
||||
SELECT create_reference_table('users_ref_test_table');
|
||||
create_reference_table
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
-- Test checks whether constraints of distributed tables can be adjusted using
|
||||
-- the ALTER TABLE ... ADD CONSTRAINT ... command.
|
||||
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1450000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_placement_placementid_seq RESTART 1450000;
|
||||
SET citus.next_shard_id TO 1450000;
|
||||
SET citus.next_placement_id TO 1450000;
|
||||
|
||||
-- Check "PRIMARY KEY CONSTRAINT"
|
||||
CREATE TABLE products (
|
||||
|
@ -420,6 +420,9 @@ SELECT "Constraint", "Definition" FROM table_checks WHERE relid='products'::regc
|
|||
SELECT "Constraint", "Definition" FROM table_checks WHERE relid='public.products_1450034'::regclass;
|
||||
|
||||
\c - - - :master_port
|
||||
SET citus.next_shard_id TO 1450038;
|
||||
SET citus.next_placement_id TO 1450038;
|
||||
|
||||
DROP TABLE products;
|
||||
|
||||
SET citus.shard_count to 2;
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
-- test insert select functionality for window functions
|
||||
-- ===================================================================
|
||||
|
||||
TRUNCATE agg_results;
|
||||
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -17,11 +15,11 @@ FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- the same test with different syntax
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -33,11 +31,11 @@ FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- similar test with lag
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg, value_3_agg)
|
||||
SELECT
|
||||
user_id, time, lag_event_type, row_no
|
||||
FROM
|
||||
|
@ -49,11 +47,11 @@ FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- simple window function, partitioned and grouped by on the distribution key
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT
|
||||
user_id, rnk, tme
|
||||
FROM
|
||||
|
@ -68,11 +66,11 @@ FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- top level query has a group by on the result of the window function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
min(user_id), min(time), lag_event_type
|
||||
FROM
|
||||
|
@ -86,11 +84,11 @@ GROUP BY
|
|||
lag_event_type;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- window functions should work along with joins as well
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -104,11 +102,11 @@ SELECT * FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- two window functions in a single subquery should work fine as well
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -123,11 +121,11 @@ SELECT * FROM
|
|||
) as foo;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- window functions should be fine within subquery joins
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg, value_3_agg)
|
||||
SELECT sub_1.user_id, max(lag_1), max(rank_1), max(rank_2) FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -157,11 +155,11 @@ JOIN
|
|||
sub_1.user_id;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- GROUP BYs and PARTITION BYs should work fine together
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
avg(user_id), max(time), my_rank
|
||||
FROM
|
||||
|
@ -180,11 +178,11 @@ GROUP BY
|
|||
my_rank;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- aggregates in the PARTITION BY is also allows
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
avg(user_id), max(time), my_rank
|
||||
FROM
|
||||
|
@ -203,12 +201,12 @@ GROUP BY
|
|||
my_rank;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- GROUP BY should not necessarly be inclusive of partitioning
|
||||
-- but this query doesn't make much sense
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT
|
||||
avg(user_id), my_rank
|
||||
FROM
|
||||
|
@ -225,11 +223,11 @@ GROUP BY
|
|||
my_rank;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Group by has more columns than partition by which uses coordinator insert ... select
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, SUM(value_2) OVER (PARTITION BY user_id)
|
||||
|
@ -244,10 +242,10 @@ LIMIT
|
|||
10;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT user_id, max(sum) FROM (
|
||||
SELECT
|
||||
user_id, SUM(value_2) OVER (PARTITION BY user_id, value_1)
|
||||
|
@ -259,11 +257,11 @@ SELECT user_id, max(sum) FROM (
|
|||
GROUP BY user_id;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Subquery in where with window function
|
||||
INSERT INTO agg_results(user_id)
|
||||
INSERT INTO agg_results_window(user_id)
|
||||
SELECT
|
||||
user_id
|
||||
FROM
|
||||
|
@ -282,13 +280,13 @@ GROUP BY
|
|||
user_id;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Partition by with aggregate functions. This query does not make much sense since the
|
||||
-- result of aggregate function will be the same for every row in a partition and it is
|
||||
-- not going to affect the group that the count function will work on.
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, COUNT(*) OVER (PARTITION BY user_id, MIN(value_2))
|
||||
|
@ -299,11 +297,11 @@ SELECT * FROM (
|
|||
) a;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Some more nested queries
|
||||
INSERT INTO agg_results(user_id, value_2_agg, value_3_agg, value_4_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg, value_3_agg, value_4_agg)
|
||||
SELECT
|
||||
user_id, rank, SUM(ABS(value_2 - value_3)) AS difference, COUNT(*) AS distinct_users
|
||||
FROM (
|
||||
|
@ -319,10 +317,10 @@ GROUP BY
|
|||
user_id, rank;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT DISTINCT
|
||||
f3.user_id, ABS(f2.sum - f3.sum)
|
||||
|
@ -347,11 +345,11 @@ WHERE
|
|||
) a;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- test with reference table partitioned on columns from both
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
(
|
||||
|
@ -362,11 +360,11 @@ FROM
|
|||
) a;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Window functions with HAVING clause
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, rank() OVER (PARTITION BY user_id ORDER BY value_1)
|
||||
|
@ -377,11 +375,11 @@ SELECT * FROM (
|
|||
) a;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Window functions with HAVING clause which uses coordinator insert ... select
|
||||
INSERT INTO agg_results (user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
DISTINCT user_id, rank() OVER (PARTITION BY user_id ORDER BY value_1)
|
||||
|
@ -396,8 +394,8 @@ LIMIT
|
|||
10;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Window function in View works
|
||||
CREATE VIEW view_with_window_func AS
|
||||
|
@ -409,17 +407,17 @@ GROUP BY
|
|||
user_id, value_1
|
||||
HAVING count(*) > 1;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
view_with_window_func;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- Window function in View works and the query uses coordinator insert ... select
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM
|
||||
view_with_window_func
|
||||
|
@ -428,10 +426,10 @@ LIMIT
|
|||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot run avg(user_id)
|
||||
SELECT count(*) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT
|
||||
user_id, max(avg)
|
||||
FROM
|
||||
|
@ -455,10 +453,10 @@ LIMIT
|
|||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot test avg or distinct count
|
||||
SELECT count(*) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT
|
||||
user_id, max(avg)
|
||||
FROM
|
||||
|
@ -479,10 +477,10 @@ GROUP BY
|
|||
user_id;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
@ -521,10 +519,10 @@ LIMIT
|
|||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
-- since there is a limit but not order, we cannot test avg or distinct count
|
||||
SELECT count(*) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
@ -560,11 +558,11 @@ FROM (
|
|||
) AS ftop;
|
||||
|
||||
-- get some statistics from the aggregated results to ensure the results are correct
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
|
||||
TRUNCATE agg_results;
|
||||
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_window;
|
||||
TRUNCATE agg_results_window;
|
||||
|
||||
-- lets have some queries that Citus shouldn't push down
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -582,7 +580,7 @@ LIMIT
|
|||
|
||||
-- user needs to supply partition by which should
|
||||
-- include the distribution key
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -600,7 +598,7 @@ LIMIT
|
|||
|
||||
-- user needs to supply partition by which should
|
||||
-- include the distribution key
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, rnk
|
||||
FROM
|
||||
|
@ -617,7 +615,7 @@ LIMIT
|
|||
10;
|
||||
|
||||
-- w2 should not be pushed down
|
||||
INSERT INTO agg_results (user_id, value_1_agg, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_1_agg, value_2_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -634,7 +632,7 @@ LIMIT
|
|||
10;
|
||||
|
||||
-- GROUP BY includes the partition key, but not the WINDOW function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, my_rank
|
||||
FROM
|
||||
|
@ -651,7 +649,7 @@ WHERE
|
|||
my_rank > 125;
|
||||
|
||||
-- GROUP BY includes the partition key, but not the WINDOW function
|
||||
INSERT INTO agg_results (user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window (user_id, agg_time, value_2_agg)
|
||||
SELECT
|
||||
user_id, time, my_rank
|
||||
FROM
|
||||
|
@ -668,7 +666,7 @@ WHERE
|
|||
my_rank > 125;
|
||||
|
||||
-- w2 should not be allowed
|
||||
INSERT INTO agg_results (user_id, value_2_agg, value_3_agg)
|
||||
INSERT INTO agg_results_window (user_id, value_2_agg, value_3_agg)
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
|
@ -683,7 +681,7 @@ SELECT * FROM
|
|||
) as foo;
|
||||
|
||||
-- unsupported window function with an override
|
||||
INSERT INTO agg_results(user_id, agg_time, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, agg_time, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, date_trunc('day', time) as time, sum(rank) OVER w2
|
||||
|
@ -700,7 +698,7 @@ SELECT * FROM (
|
|||
) a;
|
||||
|
||||
-- Subquery in where with unsupported window function
|
||||
INSERT INTO agg_results(user_id)
|
||||
INSERT INTO agg_results_window(user_id)
|
||||
SELECT
|
||||
user_id
|
||||
FROM
|
||||
|
@ -719,7 +717,7 @@ GROUP BY
|
|||
user_id;
|
||||
|
||||
-- Aggregate function on distribution column should error out
|
||||
INSERT INTO agg_results(user_id, value_2_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_2_agg)
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
user_id, COUNT(*) OVER (PARTITION BY sum(user_id), MIN(value_2))
|
||||
|
@ -731,7 +729,7 @@ SELECT * FROM (
|
|||
|
||||
-- UNION with only one subquery which has a partition on non-distribution column should
|
||||
-- error out
|
||||
INSERT INTO agg_results(user_id, value_1_agg)
|
||||
INSERT INTO agg_results_window(user_id, value_1_agg)
|
||||
SELECT *
|
||||
FROM (
|
||||
( SELECT user_id,
|
||||
|
|
Loading…
Reference in New Issue