Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ng7Sg-0002Ji-Co for pgsql-performance@arkaria.postgresql.org; Sun, 17 Apr 2022 16:09:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ng7Se-0004Fg-Pq for pgsql-performance@arkaria.postgresql.org; Sun, 17 Apr 2022 16:09:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ng7Se-0004F2-Fw for pgsql-performance@lists.postgresql.org; Sun, 17 Apr 2022 16:09:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ng7SY-0003dt-9d for pgsql-performance@postgresql.org; Sun, 17 Apr 2022 16:09:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 23HG99pd2132752; Sun, 17 Apr 2022 12:09:09 -0400 From: Tom Lane To: Benjamin Tingle cc: pgsql-performance@postgresql.org Subject: Re: Query Planner not taking advantage of HASH PARTITION In-reply-to: References: Comments: In-reply-to Benjamin Tingle message dated "Thu, 14 Apr 2022 16:36:42 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2132750.1650211749.1@sss.pgh.pa.us> Date: Sun, 17 Apr 2022 12:09:09 -0400 Message-ID: <2132751.1650211749@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Benjamin Tingle writes: > I've recently started taking advantage of the PARTITION BY HASH feature for > my database system. It's a really great fit since my tables can get quite > large (900M+ rows for some) and splitting them up into manageable chunks > should let me upload to them without having to update an enormous index > every time. What's more, since each partition has a write lock independent > of the parent table, it should theoretically be possible to perform a > parallelized insert operation, provided the data to be added is partitioned > beforehand. > What has been disappointing is that the query planner doesn't seem to > recognize this potential. That's because there isn't any. The hash partitioning rule has basically nothing to do with any plausible WHERE condition. If you're hoping to see partition pruning happen, you need to be using list or range partitions, with operators compatible with your likely WHERE conditions. (I'm of the opinion that the hash partitioning option is more in the category of a dangerous nuisance than a useful feature. There are some around here who will argue otherwise, but they're wrong for exactly the reason that it's impossible to prune hash partitions.) regards, tom lane