pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
partition table query allocate much memory
2+ messages / 2 participants
[nested] [flat]

* partition table query allocate much memory
@ 2018-05-09 10:53 tao tony <tonytao0505@outlook.com>
  2018-05-24 08:52 ` Re: partition table query allocate much memory Alexey Bashtanov <bashtanov@imap.cc>
  0 siblings, 1 reply; 2+ messages in thread

From: tao tony @ 2018-05-09 10:53 UTC (permalink / raw)
  To: pgsql-general

hi guys,

I'm not sure it was a bug,but a query on partition table allocate nearly 100GB memory is not normal.pid :119775 as below

[cid:part1.2A42CFAD.715BF014@outlook.com]

SQL:

SELECT DISTINCT etl_source,gid FROM zh_erp.buy2 WHERE gid NOT IN (SELECT gid FROM zh_erp.goodsh);

I had modified the query to:SELECT count(DISTINCT etl_source,gid) FROM zh_erp.buy2 WHERE gid NOT IN (SELECT gid FROM zh_erp.goodsh);

This problem appear again.

buy2:102GB,438382597 rows,118 partitions.

    etl_source VARCHAR,gid INTEGER.

goodsh:20GB,24692534 rows,118 partitions.

    gid INTEGER.

dbversion:PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1), 64-bit

mem and paralle setting:

shared_buffers = 8GB

work_mem = 2GB

max_worker_processes = 48               # (change requires restart)
max_parallel_workers_per_gather = 4     # taken from max_parallel_workers
max_parallel_workers = 8                # maximum number of max_worker_processes that


I reset the work_mem:when it was 1GB or 2GB,the problem appeared,while it set  to 64NB,128MB,and 512MB,it will run in parallel mode and the memory less than 10GB.

I'm not sure it was a bug and I also cloud not explain why it allocated so much memory.Dosn't each sub partition table allocated the size of work_mem memory and not free it?

When work_mem=1GB or more,the  query plan is  a HashAggregate.otherwise it was Unique and running on parallel mode.


Thanks!


Attachments:

opnjldoagbkpfnll.png (image/png, 54.9K) download view image
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: partition table query allocate much memory
  2018-05-09 10:53 partition table query allocate much memory tao tony <tonytao0505@outlook.com>
@ 2018-05-24 08:52 ` Alexey Bashtanov <bashtanov@imap.cc>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexey Bashtanov @ 2018-05-24 08:52 UTC (permalink / raw)
  To: tao tony <tonytao0505@outlook.com>; pgsql-general

Hello Tao,

> I'm not sure it was a bug and I also cloud not explain why it 
> allocated so much memory.Dosn't each sub partition table allocated the 
> size of work_mem memory and not free it? 
It can, and it did it for hashed subPlan at least in PG 9.4, see 
https://www.slideshare.net/AlexeyBashtanov/postgresql-and-ram-usage/41
Generally, work_mem is per operation, not per query -- that's not a bug

> When work_mem=1GB or more,the  query plan is  a 
> HashAggregate.otherwise it was Unique and running on parallel mode.
>
I would appreciate if you could send full plans with ANALYZE.
I suspect it's hashed subPlan hashing goodsh.gid separately for each 
partition, but maybe something else.

NOT IN is generally tricky, both semantically and for planning, 
rewriting it into NOT EXISTS or LEFT JOIN may change the plan dramatically.

Best,
   Alexey

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-05-24 08:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-05-09 10:53 partition table query allocate much memory tao tony <tonytao0505@outlook.com>
2018-05-24 08:52 ` Alexey Bashtanov <bashtanov@imap.cc>

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