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 1klG10-000834-Jj for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Dec 2020 18:41:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1klG0T-0005TC-QH for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Dec 2020 18:40:37 +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 1klG0T-0005Sz-FG for pgsql-hackers@lists.postgresql.org; Fri, 04 Dec 2020 18:40:37 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1klG0P-0001bQ-W1 for pgsql-hackers@lists.postgresql.org; Fri, 04 Dec 2020 18:40:36 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 9B77A21C7072; Fri, 4 Dec 2020 21:40:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1607107231; bh=FICxOxyoRk2kceXhERN4UpUwVGVTOV5JS2XWB04EL1g=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=R5h99sT/WmXwg8Rsij4bnUCCEEBQVliw6F9SwFsOf2cYn6I6Zvjz61oKjQFlbdtcy a1DS6Kd7i/H+gunG1nnUDDGEGzfHUcWclPqI4QNwGM2PYHQTgBFtI98ljKEvhRPQlS ZMsDpP/GAW3XujJeKWB6XQ7jwVrw7hKFVhPwNtj4= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_42e187ec7dedcb7c2ba7022b03b4a9e1" Content-Transfer-Encoding: 7bit Date: Fri, 04 Dec 2020 21:40:31 +0300 From: Alexey Kondratov To: Justin Pryzby Cc: Michael Paquier , Alvaro Herrera , Masahiko Sawada , Steve Singer , pgsql-hackers@lists.postgresql.org, Robert Haas , Alexander Korotkov , Masahiko Sawada , Jose Luis Tallon Subject: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly In-Reply-To: <20201204012543.GW24052@telsasoft.com> References: <20201031183611.GA22691@telsasoft.com> <20201124153123.GO24052@telsasoft.com> <20201201054308.GC24052@telsasoft.com> <20201203043008.GL24052@telsasoft.com> <20201204012543.GW24052@telsasoft.com> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <30bbac97f3ebbf1642e089583e4e45ba@postgrespro.ru> X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_42e187ec7dedcb7c2ba7022b03b4a9e1 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 2020-12-04 04:25, Justin Pryzby wrote: > On Thu, Dec 03, 2020 at 04:12:53PM +0900, Michael Paquier wrote: >> > +typedef struct ReindexParams { >> > + bool concurrently; >> > + bool verbose; >> > + bool missingok; >> > + >> > + int options; /* bitmask of lowlevel REINDEXOPT_* */ >> > +} ReindexParams; >> > + >> >> By moving everything into indexcmds.c, keeping ReindexParams within it >> makes sense to me. Now, there is no need for the three booleans >> because options stores the same information, no? > > I liked the bools, but dropped them so the patch is smaller. > I had a look on 0001 and it looks mostly fine to me except some strange mixture of tabs/spaces in the ExecReindex(). There is also a couple of meaningful comments: - options = - (verbose ? REINDEXOPT_VERBOSE : 0) | - (concurrently ? REINDEXOPT_CONCURRENTLY : 0); + if (verbose) + params.options |= REINDEXOPT_VERBOSE; Why do we need this intermediate 'verbose' variable here? We only use it once to set a bitmask. Maybe we can do it like this: params.options |= defGetBoolean(opt) ? REINDEXOPT_VERBOSE : 0; See also attached txt file with diff (I wonder can I trick cfbot this way, so it does not apply the diff). + int options; /* bitmask of lowlevel REINDEXOPT_* */ I would prefer if the comment says '/* bitmask of ReindexOption */' as in the VacuumOptions, since citing the exact enum type make it easier to navigate source code. > > Regarding the REINDEX patch, I think this comment is misleading: > > |+ * Even if table was moved to new tablespace, > normally toast cannot move. > | */ > |+ Oid toasttablespaceOid = allowSystemTableMods ? > tablespaceOid : InvalidOid; > | result |= reindex_relation(toast_relid, flags, > > I think it ought to say "Even if a table's indexes were moved to a new > tablespace, its toast table's index is not normally moved" > Right ? > Yes, I think so, we are dealing only with index tablespace changing here. Thanks for noticing. > > Also, I don't know whether we should check for GLOBALTABLESPACE_OID > after > calling get_tablespace_oid(), or in the lowlevel routines. Note that > reindex_relation is called during cluster/vacuum, and in the later > patches, I > moved the test from from cluster() and ExecVacuum() to > rebuild_relation(). > IIRC, I wanted to do GLOBALTABLESPACE_OID check as early as possible (just after getting Oid), since it does not make sense to proceed further if tablespace is set to that value. So initially there were a lot of duplicative GLOBALTABLESPACE_OID checks, since there were a lot of reindex entry-points (index, relation, concurrently, etc.). Now we are going to have ExecReindex(), so there are much less entry-points and in my opinion it is fine to keep this validation just after get_tablespace_oid(). However, this is mostly a sanity check. I can hardly imagine a lot of users trying to constantly move indexes to the global tablespace, so it is also OK to put this check deeper into guts. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company --=_42e187ec7dedcb7c2ba7022b03b4a9e1 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=refactor-ExecReindex.txt Content-Disposition: attachment; filename=refactor-ExecReindex.txt; size=1605 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NvbW1hbmRzL2luZGV4Y21kcy5jIGIvc3JjL2JhY2tl bmQvY29tbWFuZHMvaW5kZXhjbWRzLmMKaW5kZXggYTI3ZjhmOWQ4My4uMGIxODg0ODE1YyAxMDA2 NDQKLS0tIGEvc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