"union all" query consumes all memory - Mailing list pgsql-hackers

From Pavel Stehule
Subject "union all" query consumes all memory
Date
Msg-id CAFj8pRDsvwsg4DZRAvE=5jouBoF11q5vU1OW9dSFxh1AVgpq6Q@mail.gmail.com
Whole thread Raw
Responses Re: "union all" query consumes all memory  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello,

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:

do $$

declare i integer;  str text='';

begin

for i in 1..1000 loop

str := str || 'union all select i,i,i from generate_series(1,50000) g(i) ';

end loop;

execute 'select 1,2,3 ' || str;

end; $$

is it expected behave?

Tested on PostgreSQL 9.1, 9.2, 9.3

It looks so all generated data are saved in memory only.

Regards

Pavel Stehule

pgsql-hackers by date:

Previous
From: Christopher Browne
Date:
Subject: Re: Extra functionality to createuser
Next
From: Tom Lane
Date:
Subject: Re: "union all" query consumes all memory