one my customer reported a "out of memory" issue. After investigation he
found a main problem in large query that uses a lot of union all queries.
He wrote a self test:
declare i integer; str text='';
for i in 1..1000 loop
str := str || 'union all select i,i,i from generate_series(1,50000) g(i) ';
execute 'select 1,2,3 ' || str;
is it expected behave?
Tested on PostgreSQL 9.1, 9.2, 9.3
It looks so all generated data are saved in memory only.