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 1qJq9C-0001B8-Tg for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Jul 2023 06:49: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 1qJq99-0007Ri-Tz for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Jul 2023 06:49:51 +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 1qJq99-0007RY-GB for pgsql-hackers@lists.postgresql.org; Thu, 13 Jul 2023 06:49:51 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qJq91-000BAo-Oe for pgsql-hackers@lists.postgresql.org; Thu, 13 Jul 2023 06:49:50 +0000 Received: from mail.postgrespro.ru (webmail.mstn.postgrespro.ru [192.168.2.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id D47AFE203D1; Thu, 13 Jul 2023 09:49:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1689230982; bh=voUFpr58Sdza8Ap48gs/s5QMWU05fKo41PyAf19hpqI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:User-Agent: Message-ID:From; b=KxgQpvPt3VNQSjDx9TXF4tUP9RYBAE+UG5UIglIGfSfPYuLR1NV+LWTvF9pTXs9pv zeyX5hfRWH28pNgfTuU202BID3c2NFDSSFsM0abEQ9NzQGQLbsdywe4HDtGdIfMrVW 5hArWe6CYMLkKZhURsXe21yE+1BEmLPs1A/0CTWGSpgIC+1N3CNCowFn115q22Qdxa MJt2oOeYrB6yJg3Z2enxPGXtw15Dx+hsiahThqmBaxLqpFnpbLSxyTVk4+oVjRLUZy txPO2yNxmYjwlPvlRKUm0qdNykBrQ4o5AY2OYBbOA/DsWgcbKXlRlwrboHPQZHTkqC SUHXOOzKSMkPg== MIME-Version: 1.0 Date: Thu, 13 Jul 2023 09:49:42 +0300 From: Alexander Pyhalov To: Justin Pryzby Cc: Ilya Gladyshev , pgsql-hackers@lists.postgresql.org, Masahiko Sawada , Michael Paquier , =?UTF-8?Q?=E6=9D=8E=E6=9D=B0=28?= =?UTF-8?Q?=E6=85=8E=E8=BF=BD=29?= , =?UTF-8?Q?=E6=9B=BE=E6=96=87=E6=97=8C=28=E4=B9=89=E4=BB=8E=29?= , Alvaro Herrera Subject: Re: CREATE INDEX CONCURRENTLY on partitioned index In-Reply-To: References: <20210226182019.GU20769@telsasoft.com> <04657227cc37b6353cf0c72bedac70cc@postgrespro.ru> <20220628183309.GD28130@telsasoft.com> <20221121030011.GU11463@telsasoft.com> <5bafee07d0e1b3ce5359d1656c90b4836d7cb6a1.camel@gmail.com> <20221204190935.GD14156@telsasoft.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <37d3f0a984a15f6465b83027eed8c588@postgrespro.ru> X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Justin Pryzby писал 2023-07-13 05:27: > On Mon, Mar 27, 2023 at 01:28:24PM +0300, Alexander Pyhalov wrote: >> Justin Pryzby писал 2023-03-26 17:51: >> > On Sun, Dec 04, 2022 at 01:09:35PM -0600, Justin Pryzby wrote: >> > > This currently handles partitions with a loop around the whole CIC >> > > implementation, which means that things like WaitForLockers() happen >> > > once for each index, the same as REINDEX CONCURRENTLY on a partitioned >> > > table. Contrast that with ReindexRelationConcurrently(), which handles >> > > all the indexes on a table in one pass by looping around indexes within >> > > each phase. >> > >> > Rebased over the progress reporting fix (27f5c712b). >> > >> > I added a list of (intermediate) partitioned tables, rather than looping >> > over the list of inheritors again, to save calling rel_get_relkind(). >> > >> > I think this patch is done. >> >> Overall looks good to me. However, I think that using 'partitioned' as >> list >> of partitioned index oids in DefineIndex() is a bit misleading - we've >> just >> used it as boolean, specifying if we are dealing with a partitioned >> relation. > > Right. This is also rebased on 8c852ba9a4 (Allow some exclusion > constraints on partitions). Hi. I have some more question. In the following code (indexcmds.c:1640 and later) 1640 rel = table_open(relationId, ShareUpdateExclusiveLock); 1641 heaprelid = rel->rd_lockInfo.lockRelId; 1642 table_close(rel, ShareUpdateExclusiveLock); 1643 SET_LOCKTAG_RELATION(heaplocktag, heaprelid.dbId, heaprelid.relId); should we release ShareUpdateExclusiveLock before getting session lock in DefineIndexConcurrentInternal()? Also we unlock parent table there between reindexing childs in the end of DefineIndexConcurrentInternal(): 1875 /* 1876 * Last thing to do is release the session-level lock on the parent table. 1877 */ 1878 UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock); 1879 } Is it safe? Shouldn't we hold session lock on the parent table while rebuilding child indexes? -- Best regards, Alexander Pyhalov, Postgres Professional