DROP TABLE IF EXISTS ndistinct;

CREATE TABLE ndistinct (
    filler1 TEXT,
    filler2 NUMERIC,
    a INT,
    b INT,
    filler3 DATE,
    c INT,
    d INT
);

-- perfectly correlated groups (leads to under-estimates)
INSERT INTO ndistinct (a, b, c, filler1)
     SELECT i/10, i/10, i/10, cash_words((i/10)::money)
       FROM generate_series(1,100000) s(i);

ANALYZE ndistinct;

SET work_mem = '64kB';
SET max_parallel_workers = 0;

EXPLAIN SELECT COUNT(*) FROM ndistinct GROUP BY a, b;

SELECT COUNT(*) FROM ndistinct GROUP BY a, b;
