--SET log_temp_files = 0;

CREATE TABLE skewed AS
SELECT generate_series(1, 1000000) % 10 AS key, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
INSERT INTO skewed
SELECT generate_series(10, 999990);
ANALYZE skewed;

CREATE TABLE small AS
SELECT generate_series(1, 500000) AS key, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
ANALYZE small;

-- sequential
SET max_parallel_workers_per_gather = 0;
SET work_mem = '1MB';
EXPLAIN  ANALYZE
SELECT COUNT(*) FROM skewed r JOIN small s USING (key);

-- parallel with parallel-oblivious hash join
SET max_parallel_workers_per_gather = 1;
SET parallel_synchronization_cost = 10000000;
SET force_parallel_mode = regress;
--SET work_mem = '512kB';
EXPLAIN ANALYZE
SELECT COUNT(*) FROM skewed r JOIN small s USING (key);

-- parallel with parallel-aware hash join
SET max_parallel_workers_per_gather = 1;
RESET parallel_synchronization_cost;
SET force_parallel_mode = regress;
--SET work_mem = '512kB';
EXPLAIN ANALYZE
SELECT COUNT(*) FROM skewed r JOIN small s USING (key);

