-- The histogram of a date column asked of a superunit summary (a table of more than one unit) is that of its calendar cells, a dim past the columns of the -- schema: the check that a dim does not belong to a list read the columns array at that dim, which an address sanitizer reports (this table, with its -- units and the layout of its schema, is the one it reports on). count(DISTINCT) of the date, global and by group, on the scan and as the normal plan. CREATE EXTENSION pg_sift; SET client_min_messages = warning; SET max_parallel_workers_per_gather = 0; SET enable_hashagg = off; SET enable_sort = off; CREATE TABLE nr AS SELECT i AS id, i % 200 AS g, (hashint4(i) & 2147483647) % 2000 AS gb, 1 + (hashint4(i + 1) & 2147483647) % 5 AS s5, (hashint4(i + 2) & 2147483647) % 64 AS z63, (hashint4(i + 3) & 2147483647) % 65 AS z64, (hashint4(i + 4) & 2147483647) % 7 - 3 AS neg, (hashint4(i + 5) & 2147483647) % 200 - 250 AS negw, (hashint4(i + 6) & 2147483647) % 512 AS w511, (hashint4(i + 7) & 2147483647) % 513 AS w512, ((hashint4(i + 8) & 2147483647) % 90)::smallint AS i2, date '2024-01-01' + (hashint4(i + 9) & 2147483647) % 400 AS dt, CASE WHEN i <= 3000 THEN i % 5 ELSE (hashint4(i + 10) & 2147483647) % 3000 END AS late, (hashint4(i + 11) & 2147483647) % 100000 AS wide, 'v' || (hashint4(i + 12) & 2147483647) % 1000 AS t1000, 'v' || (hashint4(i + 13) & 2147483647) % 5 AS t5, ((hashint4(i + 14) & 2147483647) % 700)::numeric / 10 AS nm, CASE WHEN i % 13 = 0 THEN NULL ELSE (hashint4(i + 15) & 2147483647) % 6 END AS nul FROM generate_series(1, 20000) i; CREATE INDEX nr_col ON nr USING sift_col (id, g, gb, s5, z63, z64, neg, negw, w511, w512, i2, dt, late, wide, t1000, t5, nm, nul); VACUUM (FREEZE, ANALYZE) nr; SELECT count(DISTINCT dt) AS dates FROM nr; CREATE TABLE got AS SELECT g, count(DISTINCT dt) AS n FROM nr GROUP BY g; SET sift.enable_agg = off; CREATE TABLE want AS SELECT g, count(DISTINCT dt) AS n FROM nr GROUP BY g; RESET sift.enable_agg; SELECT count(*) AS different FROM ((TABLE got EXCEPT TABLE want) UNION ALL (TABLE want EXCEPT TABLE got)) d; DROP TABLE got, want, nr; DROP EXTENSION pg_sift;