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 1jgAnb-0002Qo-59 for pgsql-performance@arkaria.postgresql.org; Tue, 02 Jun 2020 17:34:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgAna-0006mv-2p for pgsql-performance@arkaria.postgresql.org; Tue, 02 Jun 2020 17:34:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgAnZ-0006mo-OU for pgsql-performance@lists.postgresql.org; Tue, 02 Jun 2020 17:34:01 +0000 Received: from mail-il1-x142.google.com ([2607:f8b0:4864:20::142]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jgAnW-0006cA-Eb for pgsql-performance@lists.postgresql.org; Tue, 02 Jun 2020 17:34:01 +0000 Received: by mail-il1-x142.google.com with SMTP id 9so13668720ilg.12 for ; Tue, 02 Jun 2020 10:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=rYnVBod8OO+2HbFhswIwU4xUjQBrqCOBog3aaIV6dX0=; b=jt+TzgzK/vzXJ82GZ9gbwFi54XP+FSLsgqehG3qkOMPu0mrcSsivPIxoHunCu6PIys nUCetzg5NzVi2vMiwqKTCLnNYxHbUW40d8wpnmW0/y4zdTHf3D+ROu7q9vC1/sCM50wo EtFwsk+cITg+iQaQNSqmJfVkRe6sXpjZ71KnqOvxKEd1I0JAJdpTeqiM1Icld9sojEu7 /jZax+riikr27Q0QTTnAWEVm+i0acuak7QTO3awfYhslJ/VbLXN6Ded7pJovixReOq5B GZ2aP3uNNlUJHzNpeFpAplavKP6dldL6doiEcZek8MnZiAhpJaZltKGo8sNTwzk4wbMs RkbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=rYnVBod8OO+2HbFhswIwU4xUjQBrqCOBog3aaIV6dX0=; b=GjdRBRWrEkyVmaKcG/EOLIHb1TRFxwtQKG0TNssDy0ERdoVgNphBg+ixw5+84X7q3B meXdhJlgvtHf3cNNZ1Wv0w2r0WDyLMbhAk8vZW39xVOSWIkX3rWJBBzRKeiGHre9QCfO mm3d7+Po1kAIe5F9aV6QVNKnLk/VZE5KoJmBzRQoD1ItdEUNkAErlNty4snOAWZd3o4a xxV9CuUDOzbrPhIZOFkEkyhHFEYXA7V8q+phsKB1caLr5RP2ECy6U2shMiaAUDaMuYyW 9yPbnN0zYopPHj3p6QyYgth4ttKE/oSZc7r2v8OuzluDLEWGwOWbtYZ1dT2sQOYbQ15b hdBw== X-Gm-Message-State: AOAM533ykfi8d7xKb89vibmZ7N9hmKNiqICUuVHzVHqW92gL4R25Td/f gDyKryjqWrTRlTKw7SQaUqSmkeoE47oadg== X-Google-Smtp-Source: ABdhPJzb1pBLWIBN3IrTt7x/wFvTD/ZOfiYTDHlDsrF85JqjuNSnszcCQn+4GEoslPGZXaoHgcb+6A== X-Received: by 2002:a92:4812:: with SMTP id v18mr488625ila.78.1591119236461; Tue, 02 Jun 2020 10:33:56 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v15sm1724055ila.57.2020.06.02.10.33.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2020 10:33:55 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 1F62D800119; Tue, 2 Jun 2020 12:33:54 -0500 (CDT) Date: Tue, 2 Jun 2020 12:33:54 -0500 From: Justin Pryzby To: Oleksandr Shulgin Cc: pgsql-performance@lists.postgresql.org Subject: Re: When to use PARTITION BY HASH? Message-ID: <20200602173353.GB30144@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > To: pgsql-general@lists.postgresql.org, pgsql-performance@lists.postgresql.org Please don't cross post to multiple lists. On Tue, Jun 02, 2020 at 07:17:11PM +0200, Oleksandr Shulgin wrote: > I was reading up on declarative partitioning[1] and I'm not sure what could > be a possible application of Hash partitioning. It's a good question. See Tom's complaint here. https://www.postgresql.org/message-id/31605.1586112900%40sss.pgh.pa.us It *does* provide the benefit of smaller indexes and smaller tables, which might allow seq scans to outpeform index scans. It's maybe only useful for equality conditions on the partition key, and not for ranges. Here, it scans a single partition: postgres=# CREATE TABLE t(i int) PARTITION BY HASH(i); CREATE TABLE t1 PARTITION OF t FOR VALUES WITH (REMAINDER 0, MODULUS 3); postgres=# CREATE TABLE t2 PARTITION OF t FOR VALUES WITH (MODULUS 3, REMAINDER 1); postgres=# CREATE TABLE t3 PARTITION OF t FOR VALUES WITH (MODULUS 3, REMAINDER 2); postgres=# INSERT INTO t SELECT i%9 FROM generate_series(1,9999)i; ANALYZE t; postgres=# explain analyze SELECT * FROM t WHERE i=3; Seq Scan on t2 (cost=0.00..75.55 rows=2222 width=4) (actual time=0.021..0.518 rows=2222 loops=1) Filter: (i = 3) Rows Removed by Filter: 2222 -- Justin