pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8687: HashAggregate runs out of memory
4+ messages / 4 participants
[nested] [flat]
* BUG #8687: HashAggregate runs out of memory
@ 2013-12-20 03:09 peters@mitre.org
0 siblings, 1 reply; 4+ messages in thread
From: peters@mitre.org @ 2013-12-20 03:09 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8687
Logged by: Peter Sylvester
Email address: peters@mitre.org
PostgreSQL version: 9.3.2
Operating system: CENTOS6
Description:
I have a query which causes out of memory conditions with a HashAggregate
plan.
The query involves a join between a 10M row table and a 1K row table,
work_mem=300MB, process space goes over 6GB then machine runs out of memory
and swap and the OS kills the back end process.
I have a test script which I can upload to recreate the issue.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #8687: HashAggregate runs out of memory
@ 2013-12-23 14:40 Michael Paquier <michael.paquier@gmail.com>
parent: peters@mitre.org
0 siblings, 1 reply; 4+ messages in thread
From: Michael Paquier @ 2013-12-23 14:40 UTC (permalink / raw)
To: peters@mitre.org; +Cc: pgsql-bugs
On Fri, Dec 20, 2013 at 12:09 PM, <peters@mitre.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 8687
> Logged by: Peter Sylvester
> Email address: peters@mitre.org
> PostgreSQL version: 9.3.2
> Operating system: CENTOS6
> Description:
>
> I have a query which causes out of memory conditions with a HashAggregate
> plan.
>
>
> The query involves a join between a 10M row table and a 1K row table,
> work_mem=300MB, process space goes over 6GB then machine runs out of memory
> and swap and the OS kills the back end process.
>
> I have a test script which I can upload to recreate the issue.
And this would be welcome. In this case the most interesting part is
the test case you could provide, perhaps this could show up some
memory not free'd in the code path you use for your query. It is hard
to tell what might be going wrong in your case, so first are you sure
that you weren't trapped by the fact that work_mem allocates its
amount of memory for each sort/limit/hash operation?
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #8687: HashAggregate runs out of memory
@ 2013-12-23 14:48 Sylvester, Peter A. <peters@mitre.org>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Sylvester, Peter A. @ 2013-12-23 14:48 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
Michael,
Attached is the script for reproducing the problem that I was seeing.
The actual update was being run from a single plsql session, so I don't think multiple work_mem areas would have been allocated.
Note that the join produces more records than the larger table, which is likely a contributor to the issue.
--Peter
-----Original Message-----
From: Michael Paquier [mailto:michael.paquier@gmail.com]
Sent: Monday, December 23, 2013 9:40 AM
To: Sylvester, Peter A.
Cc: pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #8687: HashAggregate runs out of memory
On Fri, Dec 20, 2013 at 12:09 PM, <peters@mitre.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 8687
> Logged by: Peter Sylvester
> Email address: peters@mitre.org
> PostgreSQL version: 9.3.2
> Operating system: CENTOS6
> Description:
>
> I have a query which causes out of memory conditions with a HashAggregate
> plan.
>
>
> The query involves a join between a 10M row table and a 1K row table,
> work_mem=300MB, process space goes over 6GB then machine runs out of memory
> and swap and the OS kills the back end process.
>
> I have a test script which I can upload to recreate the issue.
And this would be welcome. In this case the most interesting part is
the test case you could provide, perhaps this could show up some
memory not free'd in the code path you use for your query. It is hard
to tell what might be going wrong in your case, so first are you sure
that you weren't trapped by the fact that work_mem allocates its
amount of memory for each sort/limit/hash operation?
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
pg_hashagg_memory_issue.txt (text/plain, 2.1K) download
--postgresql HashAggregate memory problem test case for PostgreSQL 9.3.1, 9.3.2
--reported as bug ID #8687
create unlogged table table1 (key1 integer, text1 text, text2 text, val1 integer, val2 integer);
create unlogged table table2 (val3 integer, val4 integer);
create unlogged table table3 (text1 text, val3 integer);
create or replace function load_test_tables() returns boolean as $$
declare
k1 integer;
begin
perform setseed(0.12345);
--10M rows
for k1 in 1..10000000 loop
insert into table1 values(k1, random()::text, random()::text, (1000*random())::integer, (1000*random())::integer);
end loop;
for k1 in 1..1000 loop
insert into table2 values(k1, k1+10);
end loop;
return true;
end;
$$ language plpgsql;
truncate table table1;
truncate table table2;
--this will take several minutes...
select load_test_tables();
create unique index idx_table2_val3 on table2(val3);
vacuum analyze table1;
vacuum analyze table2;
--might need to adjust this upward to get HashAggregate plan
set work_mem='300MB';
--monitor background processes using top
--virtual process memory will go from about 400MB to over 6GB roughly adding 100MB per second.
--my VM is 4GM memory plus 4GB swap and OS will kill the postgres process when out of memory.
truncate table table3;
insert into table3
--explain
select distinct t1.key1, t2.val3
from table1 t1, table2 t2
where upper(t1.text2) like '0.1%'
and t2.val3 between t1.val1 and t1.val2+10;
/*
QUERY PLAN
----------------------------------------------------------------------------------------------------
HashAggregate (cost=375535.78..431091.34 rows=5555556 width=8)
-> Nested Loop (cost=0.15..347758.00 rows=5555556 width=8)
-> Seq Scan on table1 t1 (cost=0.00..173625.00 rows=50000 width=12)
Filter: (upper(text2) ~~ '0.1%'::text)
-> Index Only Scan using idx_table2_val3 on table2 t2 (cost=0.15..2.37 rows=111 width=4)
Index Cond: ((val3 >= t1.val1) AND (val3 <= (t1.val2 + 10)))
*/
^ permalink raw reply [nested|flat] 4+ messages in thread
* BUG #8687: HashAggregate runs out of memory
@ 2013-12-25 18:28 Jeff Janes <jeff.janes@gmail.com>
parent: Sylvester, Peter A. <peters@mitre.org>
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Janes @ 2013-12-25 18:28 UTC (permalink / raw)
To: Sylvester, Peter A. <peters@mitre.org>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
On Monday, December 23, 2013, Sylvester, Peter A. wrote:
> Michael,
>
> Attached is the script for reproducing the problem that I was seeing.
> The actual update was being run from a single plsql session, so I don't
> think multiple work_mem areas would have been allocated.
> Note that the join produces more records than the larger table, which is
> likely a contributor to the issue.
>
Just doing the select is sufficient to show the problem, inserting the
result into another table is not necessary.
Did this work in a previous version of PostgreSQL? Otherwise, I don't
think that there is anything very interesting going on. It thinks the
result will be 5 million rows, but instead it is 171 million. So the hash
table takes up a lot more memory than it thought it would.
You are unlikely to get good selectivity estimates when applying the like
operator to a function's results, as it doesn't store histograms for that.
So, try to avoid doing that where selectivity estimates are important.
You could store the upper version in its own column, for example. Or you
could build a function-based index on upper(text2). Either one would
provide the stats necessary to come up with better estimates, and the index
might be useful in its own right as well.
I would say that this is not really a bug. There is an opportunity for
improvement, such as hybrid hashing or dynamically switching from one plan
to another when it realizes things are going awry, but I doubt those will
happen any time soon, nor will they be back-patched to existing versions
if/when they are implemented.
Cheers,
Jeff
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2013-12-25 18:28 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-20 03:09 BUG #8687: HashAggregate runs out of memory peters@mitre.org
2013-12-23 14:40 ` Michael Paquier <michael.paquier@gmail.com>
2013-12-23 14:48 ` Sylvester, Peter A. <peters@mitre.org>
2013-12-25 18:28 ` Jeff Janes <jeff.janes@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox