I have the following table:
CREATE FOREIGN TABLE public.t_censo
(
prefecture text ,
gender text ,
population integer )
SERVER cstore_server
OPTIONS (compression 'pglz');
ALTER FOREIGN TABLE public.t_censo
OWNER TO colap;
I also have the same table created as a regular Postgres table.
When I ran this query in cstore it takes about 43 minutes to run:
SELECT gender, prefecture, SUM(population) , COUNT(*) AS _meta_count FROM t_censo GROUP BY gender, prefecture ORDER BY gender, prefecture
Here's the explain plan:
"GroupAggregate (cost=38515902.32..40076329.92 rows=40000 width=80)"
" Group Key: genero, prefectura"
" -> Sort (cost=38515902.32..38827907.84 rows=124802208 width=68)"
" Sort Key: genero, prefectura"
" -> Foreign Scan on t_censo (cost=0.00..1257718.83 rows=124802208 width=68)"
" CStore File: /var/lib/postgresql/9.6/main/cstore_fdw/17180/2496283"
" CStore File Size: 105907261"
The same query ran against the Postgres table tooks 3 minutes to execute.
The data is ordered by both, prefecture and gender.
So, there's something really strange here because this should be a fast case for a column oriented storage.
Regards