CREATE TABLE IF NOT EXISTS timeseries AS (
SELECT d::date, extract(day FROM d) AS day, extract(month FROM d) AS month, extract(year from d) AS year, x from generate_series(now() - interval '365 days',  now(), '1 day') AS days(d), generate_series(1,27000) AS x(x)
);

CREATE INDEX IF NOT EXISTS timeseries_d_idx ON timeseries(d);

SET enable_hashjoin TO off;  -- just to make sure we see the merge join we stumbled over this with

EXPLAIN (ANALYZE,VERBOSE,TIMING,BUFFERS,COSTS)
WITH oneyear AS 
--MATERIALIZED 
(
SELECT d::date AS d, extract(day FROM d) AS day, extract(month FROM d) AS month, extract(year from d) AS year FROM generate_series(now() - interval '365 days',  now(), '1 day') y(d)
)
SELECT t.* FROM timeseries t JOIN oneyear y ON t.d = y.d;
