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 1jhtgL-0007ug-7Y for pgsql-performance@arkaria.postgresql.org; Sun, 07 Jun 2020 11:41:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jhtgK-0004TC-0i for pgsql-performance@arkaria.postgresql.org; Sun, 07 Jun 2020 11:41:40 +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 1jhtgJ-0004Pl-PD for pgsql-performance@lists.postgresql.org; Sun, 07 Jun 2020 11:41:39 +0000 Received: from mout.perfora.net ([74.208.4.196]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhtgH-0002tQ-0C for pgsql-performance@lists.postgresql.org; Sun, 07 Jun 2020 11:41:38 +0000 Received: from [192.168.1.143] ([98.169.208.7]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0MXJkR-1jTpIk3gG5-00WArV; Sun, 07 Jun 2020 13:41:31 +0200 Subject: Re: When to use PARTITION BY HASH? To: Imre Samu Cc: Oleksandr Shulgin , pgsql-performance@lists.postgresql.org References: From: MichaelDBA Message-ID: <1de60053-ac43-87f3-288a-55b3f31d67f7@sqlexec.com> Date: Sun, 7 Jun 2020 07:41:28 -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: multipart/alternative; boundary="------------8F93F1AAEBE53039DF0B9759" Content-Language: en-US X-Provags-ID: V03:K1:WtdwaHgaaq1noj5heTumipIYKdejrGh3IlkFRXvoM8Hu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DGZ0HOAUN8T1UbcZePpr9T6Iu5P3jffg9o1Y7LMz6 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------8F93F1AAEBE53039DF0B9759 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit The article referenced below assumes a worst case scenario for bulk-loading with hash partitioned tables.  It assumes that the values being inserted are in strict ascending or descending order with no gaps (like a sequence number incrementing by 1), thereby ensuring every partition is hit in order before repeating the process.  If the values being inserted are not strictly sequential with no gaps, then the performance is much better.  Obviously, what part of the tables and indexes are in memory has a lot to do with it as well. Regards, Michael Vitale Imre Samu wrote on 6/5/2020 7:48 AM: > > "Bulk loads ...", > > As I see - There is an interesting bulkload benchmark: > > "How Bulkload performance is affected by table partitioning in > PostgreSQL" by Beena Emerson (Enterprisedb, December 4, 2019 ) > /SUMMARY: This article covers how benchmark tests can be used to > demonstrate the effect of table partitioning on performance. Tests > using range- and hash-partitioned tables are compared and the reasons > for their different results are explained: >                  1. Range partitions >            2. Hash partitions >                  3. Combination graphs >                4. Explaining the behavior >                  5. Conclusion/ > / > / > /"For the hash-partitioned table, the first value is inserted in the > first partition, the second number in the second partition and so on > till all the partitions are reached before it loops back to the first > partition again until all the data is exhausted. Thus it exhibits the > worst-case scenario where the partition is repeatedly switched for > every value inserted. As a result, the number of times the partition > is switched in a range-partitioned table is equal to the number of > partitions, while in a hash-partitioned table, the number of times the > partition has switched is equal to the amount of data being inserted. > This causes the massive difference in timing for the two partition > types."/ > > https://www.enterprisedb.com/postgres-tutorials/how-bulkload-performance-affected-table-partitioning-postgresql > > Regards, >  Imre > --------------8F93F1AAEBE53039DF0B9759 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit The article referenced below assumes a worst case scenario for bulk-loading with hash partitioned tables.  It assumes that the values being inserted are in strict ascending or descending order with no gaps (like a sequence number incrementing by 1), thereby ensuring every partition is hit in order before repeating the process.  If the values being inserted are not strictly sequential with no gaps, then the performance is much better.  Obviously, what part of the tables and indexes are in memory has a lot to do with it as well.

Regards,
Michael Vitale

Imre Samu wrote on 6/5/2020 7:48 AM:
> "Bulk loads ...",

As I see - There is an interesting bulkload benchmark:    

"How Bulkload performance is affected by table partitioning in PostgreSQL" by Beena Emerson (Enterprisedb, December 4, 2019 )
SUMMARY: This article covers how benchmark tests can be used to demonstrate the effect of table partitioning on performance. Tests using range- and hash-partitioned tables are compared and the reasons for their different results are explained:
                 1. Range partitions
                 2. Hash partitions
                 3. Combination graphs
                 4. Explaining the behavior
                 5. Conclusion

"For the hash-partitioned table, the first value is inserted in the first partition, the second number in the second partition and so on till all the partitions are reached before it loops back to the first partition again until all the data is exhausted. Thus it exhibits the worst-case scenario where the partition is repeatedly switched for every value inserted. As a result, the number of times the partition is switched in a range-partitioned table is equal to the number of partitions, while in a hash-partitioned table, the number of times the partition has switched is equal to the amount of data being inserted. This causes the massive difference in timing for the two partition types."
Regards,
 Imre

--------------8F93F1AAEBE53039DF0B9759--