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 1nrj0J-0004fN-F8 for pgsql-docs@arkaria.postgresql.org; Thu, 19 May 2022 16:27:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nrj0H-0006xn-Er for pgsql-docs@arkaria.postgresql.org; Thu, 19 May 2022 16:27:57 +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 1nriob-0003Ql-DS for pgsql-docs@lists.postgresql.org; Thu, 19 May 2022 16:15:53 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nrioZ-00034n-6k for pgsql-docs@lists.postgresql.org; Thu, 19 May 2022 16:15:53 +0000 Received: by mail-oi1-x236.google.com with SMTP id v65so7012885oig.10 for ; Thu, 19 May 2022 09:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=AF91jo3//YJauvjAMu9x2j3fHEiepVtKlbJwLo6bsHI=; b=dVG7jNM2dOozPF+mp/zXYrA8spn5nW3M2qQJkZoc2ZSOjUmlzdB4hx2+pZMxthdiE/ Vjic1yJiY42h25FTvz2JqM71Y4kX5yH/Z8CeFGFI8a2MaXVxVoVjpeCDPC+KyzEEVdLx hghJEJJxqvkfGDrUfo1alG5ULRzLcHRrnwkr2dxnd4PHLqr7eFhORzCLTtHQWiq7o1QQ OWivx1tGC6SPwUXj2bf9HSmnhZADVlkdBzRHzSyiL4jZkJw5TiEpzRlsE2/gHcX4lQsa nMUx7Csgnsa6wSqsKsB0K0+pfVci7+cqQ1iGLzbkzdGI5HlNi/0WixaDFkpsJMuIM1Vh zWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=AF91jo3//YJauvjAMu9x2j3fHEiepVtKlbJwLo6bsHI=; b=AWvXM0wIX9L6bKLi3i722hf5yI8/4eQgS+MTgBb8FtehnVdHQNcrxStbwgxi7IhhqN GzZ5UiyfAVCaNQwv6ewM7jSiMDuMLZX4BYmev3g9uPReJshzOVD0Z6kfEdpvKda1jvNb DTwKvWJ9kgTnJxM4aypy4MW1jGggEeRuflxwCuFJMgyKvj8kOkeQgZA5PwCl3l4VWDZD FwMlUKyxI9Y28W7ADzAArv02C3cwI1UWu4fL+y1BXFe20rwdtH2dXLTMQGEi9Zw5z6ht xxlnlSW4jhT0mQnzkF1fjfP0SWbofQdoirbnrOWf1eDasB21kzlHWxYN7r15QdfW2Nj7 qq2A== X-Gm-Message-State: AOAM531PN0+eCATo6x0jenSXDVF5o+a7LbyGJkbyeY/0pSbPwr5XrwGw VqXtaFZg3P3obZUxdiL9sfusnsG8d2fTZQ== X-Google-Smtp-Source: ABdhPJzqEPajT3MV6FcXet/oqaO+3iMVwlSd4Uy0hTY0MtWKaX+LhbMOuu+4edL7boG5qvYDjagNBg== X-Received: by 2002:a05:6808:d4a:b0:32a:e707:96a0 with SMTP id w10-20020a0568080d4a00b0032ae70796a0mr2363052oik.297.1652976948705; Thu, 19 May 2022 09:15:48 -0700 (PDT) Received: from smtpclient.apple ([2600:100e:be1c:1558:91f7:c876:3def:741c]) by smtp.gmail.com with ESMTPSA id a16-20020a056870e35000b000f1bad20cc9sm26739oae.0.2022.05.19.09.15.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 May 2022 09:15:47 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Lauren Fliksteen Mime-Version: 1.0 (1.0) Subject: Re: INVALID index while concurrent indexing in progress? Date: Thu, 19 May 2022 09:15:45 -0700 Message-Id: <01987150-EDDC-4567-944C-370F46AE9807@gmail.com> References: Cc: Rajakavitha Kodhandapani , pgsql-docs@lists.postgresql.org In-Reply-To: To: Laurenz Albe X-Mailer: iPhone Mail (19A346) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thank you both! I think Laurenz=E2=80=99s changes make perfect sense! Sent from my iPhone > On May 19, 2022, at 8:37 AM, Laurenz Albe wrote= : >=20 > =EF=BB=BFOn Thu, 2022-05-19 at 19:02 +0530, Rajakavitha Kodhandapani wrote= : >>> I think the INVALID index can use further explanation, in particular, fr= om >>> my experience it seems like when building an index concurrently, the ind= ex >>> gets inserted and labeled invalid while the index is being built, and th= en >>> the label gets removed if it finishes successfully or gets left on the i= ndex >>> if there is a failure while building the index. It is my current >>> understanding, after experimenting, that INVALID means 'incomplete', whe= ther >>> that's because it's in progress or because it was unable to be completed= , >>> but prior to my experiment my understanding was that INVALID indicated >>> failure. >>>=20 >>> This was especially confusing when we were adding an index to a very lar= ge >>> table because we assumed the INVALID index indicated failure when we >>> couldn't find any other sign of progress or failure. >>=20 >> This is my first attempt at contributing to the documentation of PostgreS= QL. >> Here's the patch. Please let me know if any other changes need to be made= . >=20 > Thank you! Please send patches as plain text and use bottom posting. >=20 >> \cf3 @@ -665,11 +665,14 @@\cf5 Indexes:\ >> \ >> Another caveat when building a unique index concurrently is that the\= >> uniqueness constraint is already being enforced against other transac= tions\ >> \cf6 - when the second table scan begins. This means that constraint v= iolations\cf5 \ >> \cf4 + when the second table scan begins. This means that constraint v= iolations\cf5 \ >> could be reported in other queries prior to the index becoming availa= ble\ >> \cf6 - for use, or even in cases where the index build eventually fail= s. Also,\cf5 \ >> \cf6 - if a failure does occur in the second scan, the invalid<= /quote> index\cf5 \ >> \cf6 - continues to enforce its uniqueness constraint afterwards.\cf5 \= >> \cf4 + for use, or even in cases where the index build eventually fail= s. The index\cf5 \ >> \cf4 + is inserted and labeled invalid while the index i= s being built,\cf5 \ >> \cf4 + and then the label is removed if the index builds successfully.= If the index does\cf5 \ >> \cf4 + not build successfully, then the label invalid r= emains. Also, if a\cf5 \ >> } >=20 > I don't think that this information should be added to a paragraph that > focuses on uniqueness checks in concurrent index builds. >=20 > Actually, most of the information is already there. To quote from the pag= e: >=20 > If a problem arises while scanning the table, such as a deadlock or a uni= queness violation > in a unique index, the CREATE INDEX command will fail but leave behind an= =E2=80=9Cinvalid=E2=80=9D index. >=20 > How about the following patch to emphasize the role of "invalid": >=20 > diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_= index.sgml > index d3102a87d9..fee2c61e5e 100644 > --- a/doc/src/sgml/ref/create_index.sgml > +++ b/doc/src/sgml/ref/create_index.sgml > @@ -622,7 +622,7 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EX= ISTS ] >=20 > > - In a concurrent index build, the index is actually entered into > + In a concurrent index build, the index is actually entered as = invalid index into > the system catalogs in one transaction, then two table scans occur in > two more transactions. Before each table scan, the index build must > wait for existing transactions that have modified the table to termina= te. > @@ -631,7 +631,7 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EX= ISTS ] scan to terminate, including transactions used by any phase of concurr= ent > index builds on other tables, if the indexes involved are partial or h= ave > columns that are not simple column references. > - Then finally the index can be marked ready for use, > + Then finally the index can be marked valid and ready f= or use, > and the CREATE INDEX command terminates. > Even then, however, the index may not be immediately usable for querie= s: > in the worst case, it cannot be used as long as transactions exist tha= t >=20 > Yours, > Laurenz Albe