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 1p3doU-0005Bb-Mf for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 13:53:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3doT-00020X-7Z for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Dec 2022 13:53:17 +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 1p3doS-00020N-SZ for pgsql-hackers@lists.postgresql.org; Fri, 09 Dec 2022 13:53:16 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3doQ-0003tq-Br for pgsql-hackers@lists.postgresql.org; Fri, 09 Dec 2022 13:53:16 +0000 Received: by mail-lf1-x136.google.com with SMTP id d6so7097154lfs.10 for ; Fri, 09 Dec 2022 05:53:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=AHcfS95m3E/Gjzit+844rOS4ASdKu3bm6XSZyc+iNd8=; b=Az2vA/AtEMnYIT7X8+zJHMbPr7jOPqYVMnfCg/0yzW7uZhEoxsCdvF6OzuTddHPVEA KqU79OuLmzzMED5U+SM/nzkpF7yWD/Jz6m4rCTbNCpDHlrBXv4DY6+m4la8G0QaJk0eL AJMD+zyrNlPswb1ku3EvEEOC/jxnGGay5z9+7+eM54EzPJOOpxiHcocSIpe8enmlCBz+ LX5GJCHxqto5L4v6pEJzrz4SoXfbMRrVmZMPWR3uFHAa1lnnJxZa19uNiFgLph9UAVBe y+2CXGUWveZYjxjJycnH/r0BCitQFiN+g5+dflUqQ8y5t7SXoQOUNsAsQwAXZfJxquIt tkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AHcfS95m3E/Gjzit+844rOS4ASdKu3bm6XSZyc+iNd8=; b=xYDvCkYTFTB7lqo+bE+hSduOukD6WGcnsyXGr3anZyk8GYIB0mgz2gKU809/D2sWBw Y0vPo1qJSH7RhcjJeL7UVltynmQR+aUxzgInNV3QFub8YY3mAstnrqsaI5GbPL/vNQLl +ev2oCvegaFqHpKCqTvoxeX+r30ZarKLWeG356sKXaSw7E5R2WTct0gf6Xizjytgh6DP ywsUAcaFJDdikQou8jzf/ceRYn6zn+2u8Og+Hugy+zuKBFV8x3SXPkvrmdNvTd62r5Ml Zp6MVC8ytW1gF/yJDh/8aw26PYwswESJaEwlcZJkq77mBD+e2mEZkjUI1UB3j/LRaC7S js9w== X-Gm-Message-State: ANoB5plCm90mPuopNU5u6jlDk+yJU5LVHLrJZ1MNhkwGPwwriIq659aS +PUCzHtd1O7Q1f9dszEGJQyTYB97jTk/RsLy X-Google-Smtp-Source: AA0mqf7LNni7U7oT4OReLMdE9GUnfWdNQzGDLwpEDYbtAQwp/aDvsC8o0Gb5er8ZryQwqDCV/7ssbg== X-Received: by 2002:ac2:4909:0:b0:4aa:4788:2a1 with SMTP id n9-20020ac24909000000b004aa478802a1mr1401621lfi.37.1670593993115; Fri, 09 Dec 2022 05:53:13 -0800 (PST) Received: from [192.168.28.144] (cyclops.postgrespro.ru. [93.174.131.138]) by smtp.gmail.com with ESMTPSA id e7-20020a05651236c700b00492e5d31201sm275438lfs.7.2022.12.09.05.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 05:53:12 -0800 (PST) Message-ID: <05c08a663f357eecae09942b3939e560bcb0fc18.camel@gmail.com> Subject: Re: CREATE INDEX CONCURRENTLY on partitioned index From: Ilya Gladyshev To: Justin Pryzby Cc: Alexander Pyhalov , pgsql-hackers@lists.postgresql.org, Masahiko Sawada , Michael Paquier , =?UTF-8?Q?=E6=9D=8E=E6=9D=B0=28=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 Date: Fri, 09 Dec 2022 17:53:10 +0400 In-Reply-To: <20221204190935.GD14156@telsasoft.com> References: <20201129202221.GA9477@telsasoft.com> <20210128143013.GC7450@telsasoft.com> <20210226182019.GU20769@telsasoft.com> <04657227cc37b6353cf0c72bedac70cc@postgrespro.ru> <20220628183309.GD28130@telsasoft.com> <20221121030011.GU11463@telsasoft.com> <5bafee07d0e1b3ce5359d1656c90b4836d7cb6a1.camel@gmail.com> <20221204190935.GD14156@telsasoft.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2022-12-04 at 13:09 -0600, Justin Pryzby wrote: > > This beavior is fixed.  I re-factored and re-implented to use > DefineIndex() for building indexes concurrently rather than > reindexing. > That makes the patch smaller, actually, and has the added benefit of > splitting off the "Concurrently" part of DefineIndex() into a > separate > function. Nice, I think it turned out pretty concise. I played around with the patch quite a bit, didn't find any major problems, the only minor thing that I can note is that we should skip the top parent index itself in the loop not to increment the pg_stat counter, something like this: diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index cfab45b999..9049540b5b 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1515,6 +1515,9 @@ DefineIndex(Oid relationId, Oid indrelid = lfirst_oid(lc); Oid tabrelid = IndexGetRelation(indrelid, false); + if (indrelid == indexRelationId) + continue; + if (RELKIND_HAS_STORAGE(get_rel_relkind(indrelid)) && !get_index_isvalid(indrelid)) { > > BTW, it causes the patch to fail to apply in cfbot when you send an > additional (002) supplementary patch without including the original > (001) patch.  You can name it *.txt to avoid the issue. > > https://wiki.postgresql.org/wiki/Cfbot#Which_attachments_are_considered_to_be_patches.3F > > Thanks for looking. > My bad, didn't know about this, thanks for the link. On a side note, I noticed that reindex behaviour is strange on partitioned tables, it doesn't mark partitioned tables as valid after reindexing children, as I could understand from the code and mailing lists, this is the intended behaviour, but I can't quite understand the rationale for it, do you know why it is done this way?