Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLlzr-0005F1-8G for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 08:53:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLlzp-00057h-L5 for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 08:53:17 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLlzo-00057S-C1 for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 08:53:17 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLlzl-00020e-1p for pgsql-general@postgresql.org; Thu, 24 May 2018 08:53:15 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6F17921D2B; Thu, 24 May 2018 04:53:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 24 May 2018 04:53:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imap.cc; h= content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=0pMBxqjjOZ2Nwe65a4lpo57+MEgsihYBHyDwUhncLhA=; b=KO40jQkx OVij6vSwzXO1PuAx5kpFSfpUFa+5UOEAqIyM7q3+k175aK9qJVyWycDU/hCl5sTu nw6WMUZfmOqDumUu13aoT9oNw3w04jNI2uqHllqKBlgU4pJdtVkUSocalGyhwMqC F9Zz1t288eAn/0eSSMPClYuPicLHas0RbRfVxf+qmgOt2qnW4+T7I2N3vNRLuaem xVnSsK5bJUvIxlJx38W9VM9pJu6VHs2V3yzUc+/pGjx1Ys/SivtpiDOUBokKeN9q h51HadzO6LzH1gLgrtZviFoZCx82JDK2oaYJcQP9cFxDsmiju6zIpTKcOdhpLQ+J K8JWe1qijk15fA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=0pMBxqjjOZ2Nwe65a4lpo57+MEgsi hYBHyDwUhncLhA=; b=ktBBJ57bJkmuPf70VWGHV8sZtt4jybCQ9yXmfZ8ow+bik yNYhubkseMMy5xo6PBgoWMnXahlcFPwWVM7CnqIh3IQRfjwMKy1bS74epcCvIp5v KyAIxkFNnNz2vhm41JBcFaeglagsAMJIYraThrOc+gs78bCbjZcfzpRTMMWRXnT/ m9n94JxpZ4KQt6BQmd3dcx0C/K/XoDWoSegUf6DN+1grmwTqrCpJEivicRf3m9is o7/VGPQ7tqYzL12lYOruSphx2DgQJw+JtXPhtZ6bj5iVDAQp8p40WAGykRExB8ce ryvoSvSv6eqinPpf+TBtPx8YCsDUCquLyXHt/O8Ww== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [10.2.33.124] (unknown [185.25.33.70]) by mail.messagingengine.com (Postfix) with ESMTPA id D821EE442F; Thu, 24 May 2018 04:53:10 -0400 (EDT) Subject: Re: partition table query allocate much memory To: tao tony , "pgsql-general@postgresql.org" References: From: Alexey Bashtanov Message-ID: Date: Thu, 24 May 2018 09:52:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------BD129983F94059DEEDB0DF39" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------BD129983F94059DEEDB0DF39 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------BD129983F94059DEEDB0DF39 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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
--------------BD129983F94059DEEDB0DF39--