-- test for aggregate pushdown explain (costs off, verbose) select count(distinct a) from multiprimary; QUERY PLAN --------------------------------------------------------------------- Foreign Scan Output: (count(DISTINCT a)) SQLite query: SELECT count(DISTINCT `a`) FROM main."multiprimary" (3 rows) explain (costs off, verbose) select sum(b),max(b), min(b), avg(b) from multiprimary; QUERY PLAN ---------------------------------------------------------------------------------------- Foreign Scan Output: (sum(b)), (max(b)), (min(b)), (avg(b)) SQLite query: SELECT sum(`b`), max(`b`), min(`b`), avg(`b`) FROM main."multiprimary" (3 rows) explain (costs off, verbose) select sum(b+5)+2 from multiprimary group by b/2 order by b/2; QUERY PLAN -------------------------------------------------------------------------------------------------- Sort Output: ((sum((b + 5)) + '2'::numeric)), ((b / 2)) Sort Key: ((multiprimary.b / 2)) -> Foreign Scan Output: ((sum((b + 5)) + '2'::numeric)), ((b / 2)) SQLite query: SELECT (sum((`b` + 5)) + 2), (`b` / 2) FROM main."multiprimary" GROUP BY 2 (6 rows) explain (costs off, verbose) select sum(a) from multiprimary group by b having sum(a) > 0; QUERY PLAN -------------------------------------------------------------------------------------------------- Foreign Scan Output: (sum(a)), b SQLite query: SELECT sum(`a`), `b` FROM main."multiprimary" GROUP BY 2 HAVING ((sum(`a`) > 0)) (3 rows) explain (costs off, verbose) select sum(a) from multiprimary group by b having avg(a^2) > 0 and sum(a) > 0; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- HashAggregate Output: sum(a), b Group Key: multiprimary.b Filter: ((avg(((multiprimary.a)::double precision ^ '2'::double precision)) > '0'::double precision) AND (sum(multiprimary.a) > '0'::numeric)) -> Foreign Scan on public.multiprimary Output: a, b, c SQLite query: SELECT `a`, `b` FROM main."multiprimary" (7 rows) -- stddev and variance are not pushed down explain (costs off, verbose) select stddev(a) from multiprimary; QUERY PLAN ----------------------------------------------------------- Aggregate Output: stddev(a) -> Foreign Scan on public.multiprimary Output: a, b, c SQLite query: SELECT `a` FROM main."multiprimary" (5 rows) explain (costs off, verbose) select sum(a) from multiprimary group by b having variance(a) > 0; QUERY PLAN ---------------------------------------------------------------- HashAggregate Output: sum(a), b Group Key: multiprimary.b Filter: (variance(multiprimary.a) > '0'::numeric) -> Foreign Scan on public.multiprimary Output: a, b, c SQLite query: SELECT `a`, `b` FROM main."multiprimary" (7 rows)