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 1mTYZw-0005fV-Uf for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Sep 2021 23:56:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTYZv-0002sc-HM for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Sep 2021 23:56:35 +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 1mTYZv-0002sU-3j for pgsql-hackers@lists.postgresql.org; Thu, 23 Sep 2021 23:56:35 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTYZr-0002bH-2V for pgsql-hackers@lists.postgresql.org; Thu, 23 Sep 2021 23:56:34 +0000 Received: by mail-io1-xd2a.google.com with SMTP id q3so10326739iot.3 for ; Thu, 23 Sep 2021 16:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=v/6tjgifogZy/SjU7sjh1b8BjkbNXzwFLV1LHUxJTHs=; b=GQYPRTxO/X+zJioZDWWEIoYvpFul5InW8iqHRgTiAct9/6IpdUjVPOKwIiFh3YLIlu gxaNw9gj4uJYYUv8uvpREUKLtpnp3syqZREaTI2VheAgU63Y6DaCXCrZY3SZTH+D1ut1 7rq68yWRgcysg2iN5zsfhsVX+DsuNWw4+nyEvX3ynVC08jOnNwdt+XUWOsynAAyT1yEa NOjj+LMI/MT+RcKVzslK8J09v8QLl1GTKZaSwBMe8ViosP9ad2vWCKZK0Oq9B4amp1Ue 1I5i6U+yXMfApPORqqHiJSYNwPbgD8XegDXxuRZEzChaB4bCYfFch5ZPY8F3FR4jaLjp Z+ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=v/6tjgifogZy/SjU7sjh1b8BjkbNXzwFLV1LHUxJTHs=; b=UJuXN6LtAGF0CLc5lsG4Ev9Z1bMaGGAXVu3XIv6YGkhXr/xp90hLackgy8tNPMUE3R EMTmIOHVpy+GRbSYm8l9OE3ysxfau7NymF8CHVmgc772KSczqcDtMro8RrQ/Jb3tQ4uq 5iBkm0sIwEaXHEkimAGC2AowX8Pvh0HeTzS9F72HYHtP5sVBSFCbbEnW1SbHyfErVwIB BnuIzLbZc1EzBsXn0dqvtXmNxpCOwmVrozA69njHgem0znyZyatjPDhfnjxymP0Q9I1J TbMJ55Q7Qr7BxHxrwzj76Natp25HP4V6MZXhOzRoSOos/c0hdj9/0Bi6Q5bhEoxwRtXl OevQ== X-Gm-Message-State: AOAM531t/jc1JK4s7R48tsolGIUKbK/9cmftbbc5TnX9NU1uh96QxaRf 28pTUFA/oLoaOyvoG4HhbD1SKw== X-Google-Smtp-Source: ABdhPJzK6qrzY0W5Xe7hfGd/u7FmZSterGei3Cnm60/K9TJqnoQt67CngOeJUoxEYYqFtEC4jJFxwg== X-Received: by 2002:a05:6638:cd8:: with SMTP id e24mr6459621jak.53.1632441388324; Thu, 23 Sep 2021 16:56:28 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v63sm574597ioe.17.2021.09.23.16.56.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Sep 2021 16:56:27 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 666FF800B38; Thu, 23 Sep 2021 18:56:26 -0500 (CDT) Date: Thu, 23 Sep 2021 18:56:26 -0500 From: Justin Pryzby To: Matthias van de Meent Cc: Alvaro Herrera , Michael Paquier , =?utf-8?B?5p2O5p2wKOaFjui/vSk=?= , pgsql-hackers@lists.postgresql.org, =?utf-8?B?5pu+5paH5peMKOS5ieS7jik=?= , Zhihong Yu Subject: Re: CLUSTER on partitioned index Message-ID: <20210923235626.GJ831@telsasoft.com> References: <20210402200314.GA6592@telsasoft.com> <202107210027.vfv6wn3hvfer@alvherre.pgsql> <20210912201029.GG26465@telsasoft.com> 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: Archived-At: Precedence: bulk On Thu, Sep 23, 2021 at 08:18:41PM +0200, Matthias van de Meent wrote: > On Sun, 12 Sept 2021 at 22:10, Justin Pryzby wrote: > > > > On Tue, Jul 20, 2021 at 08:27:02PM -0400, Alvaro Herrera wrote: > > > I have to wonder if there really *is* a use case for CLUSTER in the > > > first place on regular tables, let alone on partitioned tables, which > > > are likely to be large and thus take a lot of time. > > > > The cluster now is done one partition at a time, so it might take a long time, > > but doesn't lock the whole partition heirarchy. Same as VACUUM (since v10) and > > (since v14) REINDEX. > > Note: The following review is based on the assumption that this v11 > revision was meant to contain only one patch. I put this up as a note, > because it seemed quite limited when compared to earlier versions of > the patchset. Alvaro's critique was that the patchset was too complicated for what was claimed to be a marginal feature. My response was to rearrange the patchset to its minimal form, supporting CLUSTER without marking the index as clustered. > I noticed that you store the result of find_all_inheritors(..., > NoLock) in get_tables_to_cluster_partitioned, without taking care of > potential concurrent partition hierarchy changes that the comment on > find_all_inheritors warns against or documenting why it is safe, which > sounds dangerous in case someone wants to adapt the code. One problem > I can think of is that only storing reloid and indoid is not > necessarily safe, as they might be reused by drop+create table running > parallel to the CLUSTER command. The parallel code in vacuum is expand_vacuum_rel(), which is where the corresponding things happens for vacuum full. This patch is to make cluster() do all the same stuff before calling cluster_rel(). What VACUUM tries to do is to avoid erroring if a partition is dropped while cluster is running. cluster_rel() does the same thing by calling cluster_multiple_rels() ,which uses CLUOPT_RECHECK. If the OIDs wrapped around, I think existing vacuum could accidentally process a new table with the same OID as a dropped partition. I think cluster would *normally* catch that case and error in check_index_is_clusterable(): | Check that index is in fact an index on the given relation Arguably VACUUM FULL could call cluster() (not cluster_rel()) and pass the partitioned table rather than first expanding it. But non-full vacuum needs to expand partitioned tables anyway. > Apart from that, I think it would be useful (though not strictly > necessary for this patch) if you could adapt the current CLUSTER > progress reporting to report the progress for the whole partition > hierarchy, instead of a new progress report for each relation, as was > the case in earlier versions of the patchset. Yea, but this is already true for VACUUM FULL (which uses CLUSTER and supports partitioned tables since v10) and REINDEX. See also https://postgr.es/m/20210216064214.GI28165@telsasoft.com My goal is to present a minimal patch and avoid any nonessential complexity. > The v11 patch seems quite incomplete when compared to previous > discussions, or at the very least is very limited (no ALTER TABLE > clustering commands for partitioned tables, but `CLUSTER ptable USING > pindex` is supported). If v11 is the new proposed direction for ptable > clustering, could you also document these limitations in the > cluster.sgml and alter_table.sgml docs? You said it's less complete, but it's is due to deliberate reduction in scope. cluster.sgml says: + Clustering a partitioned table clusters each of its partitions using the + partition of the specified partitioned index (which must be specified). The ALTER restriction hasn't changed, so I didn't touch the documentation. I am still curious myself to know if this is the direction the patch should move. > > [ v11-0001-Implement-CLUSTER-of-partitioned-table.patch ] > > > diff --git a/src/test/regress/expected/cluster.out b/src/test/regress/expected/cluster.out > > ... > > +ALTER TABLE clstrpart SET WITHOUT CLUSTER; > > +ERROR: cannot mark index clustered in partitioned table > > This error message does not seem to match my expectation as a user: I > am not trying to mark an index as clustered, and for a normal table > "SET WITHOUT CLUSTER" does not fail for unclustered tables. I think > that behaviour of normal unclustered tables should be shared here as > well. At the very least, the error message should be changed. This is the pre-existing behavior. > > -DROP TABLE clstrpart; > > I believe that this cleanup should not be fully removed, but moved to > before '-- Test CLUSTER with external tuplesorting', as the table is > not used after that line. You're right - this was from when the patchset handled CLUSTER ON. Leaving the index allows testing in pg_dump - a large part of the complexity of the elided patches is to handle restoring a partitioned index, without violating the rule that partitions of an clustered index must also be clustered. I adjusted this in my local branch. Thanks for looking. I'm going to see about updating comments based on corresponding parts of vacuum and on this message itself. -- Justin