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 1jgAtH-0002cF-UL for pgsql-performance@arkaria.postgresql.org; Tue, 02 Jun 2020 17:39:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgAtG-0002HY-Pz for pgsql-performance@arkaria.postgresql.org; Tue, 02 Jun 2020 17:39:54 +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 1jgAtG-0002HM-IR; Tue, 02 Jun 2020 17:39:54 +0000 Received: from mout.perfora.net ([74.208.4.197]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgAt9-000266-9l; Tue, 02 Jun 2020 17:39:52 +0000 Received: from [192.168.1.143] ([98.169.208.7]) by mrelay.perfora.net (mreueus003 [74.208.5.2]) with ESMTPSA (Nemesis) id 0LuOAL-1iwlJJ2al5-011fAX; Tue, 02 Jun 2020 19:39:42 +0200 Subject: Re: When to use PARTITION BY HASH? To: Oleksandr Shulgin Cc: pgsql-general@lists.postgresql.org, pgsql-performance@lists.postgresql.org References: From: MichaelDBA Message-ID: <2835080c-b6ac-d13a-c788-4fd03b2c7a23@sqlexec.com> Date: Tue, 2 Jun 2020 13:39:40 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 PostboxApp/7.0.17 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Provags-ID: V03:K1:yGlga3eVz6MWT+PzKqnr4KnXQgZHscPi7I5A3UHMz6Owrz6EvfF YhY5OthJjo3Qts3e3ML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IFXhqThyI2l+vfUJMPQSwZGMFd List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I use it quite often, since I'm dealing with partitioning keys that have high cardinality, ie, high number of different values.  If your cardinality is very high, but your spacing between values is not uniform, HASH will balance your partitioned tables naturally.  If your spacing between values is consistent, perhaps RANGE partitioning would be better. Regards, Michael Vitale Oleksandr Shulgin wrote on 6/2/2020 1:17 PM: > Hi! > > I was reading up on declarative partitioning[1] and I'm not sure what > could be a possible application of Hash partitioning. > > Is anyone actually using it? What are typical use cases?  What > benefits does such a partitioning scheme provide? > > On its face, it seems that it can only give you a number of tables > which are smaller than the un-partitioned one, but I fail to see how > it would provide any of the potential advantages listed in the > documentation. > > With a reasonable hash function, the distribution of rows across > partitions should be more or less equal, so I wouldn't expect any of > the following to hold true: > - "...most of the heavily accessed rows of the table are in a single > partition or a small number of partitions." > - "Bulk loads and deletes can be accomplished by adding or removing > partitions...", > etc. > > That *might* turn out to be the case with a small number of distinct > values in the partitioning column(s), but then why rely on hash > assignment instead of using PARTITION BY LIST in the first place? > > Regards, > -- > Alex > > [1] https://www.postgresql.org/docs/12/ddl-partitioning.html >