Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rExYC-007pk5-K6 for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Dec 2023 20:15:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rExXB-0037ID-6W for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Dec 2023 20:14:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rExXA-0037I5-R4 for pgsql-hackers@lists.postgresql.org; Sun, 17 Dec 2023 20:14:44 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rExX7-00CVcP-L2 for pgsql-hackers@postgresql.org; Sun, 17 Dec 2023 20:14:43 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a1fae88e66eso249344866b.3 for ; Sun, 17 Dec 2023 12:14:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702844079; x=1703448879; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Gf1EHQXE3e9LnszUfVpNjQLa0ko8263QkM1b4kd2ZdM=; b=DRe76OaTGmHt0a+iV4UKanehw9OJdL65PmyNC0op7K7gWwy/ZAziCKYceYwuUTN77f ajT5WAdTSM6UBWAv+ZhJZprhPcrXt1h/9wypW742H4SZbW+nzjX5Z4anndAYse5otn+L Lm8PhFt6h6/zEEPypQCqmN/E8f8s6Eb9/t9ILMgjYLrE/fN7JYHAR9R24lu2eaHEQm+4 t7BEXU4TgXT06DcrUnncRBW/l3w6r2ngi3Di+f+Sd7MC7fCLsJjjYbt8FIA87hvJYhWn +I5IRLHCh2CJ5QJd0rRIalGiTtx0iMLYirebrIzkJVNs0v6kSnD9Dzcn7NJfOtCHogXB OnrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702844079; x=1703448879; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gf1EHQXE3e9LnszUfVpNjQLa0ko8263QkM1b4kd2ZdM=; b=lYbpslSYrkpojwqiLzZ1SMtkLg7i/BsUpPSobtervyhpfN/OWJYNXcBOKxSeinWKVD /aH4IuoGP5e6JL80X+lOfndkprayrcjST0/zlVaThFl1jKZ9hJxeLJkfafoF6u7APlvb EguHry4fAbKtd92b9cbqhDS8Z7hXZpBlseN/H4CjPv9X9f7SHLJ2klZnRIpU68D/jZjN TH7abWtVptt+K40tEsooC7KOWf+aF8FSCOePK/Oj2mQGIZauvpF48zkMuZ6oGTR/yQHJ ddAdIgzR/lned05sJ+7cxgfsJtcrIVUoEIU4Uye5auWN6SlKmz0FeHvMFLPXxeYolfuL w2Kw== X-Gm-Message-State: AOJu0Ywg+fPsyw92yk8hOq+ujoH/JswLLi8Un7svi0YdtZJqjLNYsrMp /8sjm+d6kTwVK0WjRPTd5wJWUuTZ3zt8kXUG4D8= X-Google-Smtp-Source: AGHT+IE8mxreVd+vHtmbO4E2vX4HLfG9ueFTjMRuIghvxAb077cQloyxu95bq6tUWUBmRfwDPQWGxqDvC5NG6o+7KRQ= X-Received: by 2002:a17:907:392:b0:a23:5730:836a with SMTP id ss18-20020a170907039200b00a235730836amr284658ejb.43.1702844079264; Sun, 17 Dec 2023 12:14:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Sun, 17 Dec 2023 21:14:27 +0100 Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Matthias van de Meent Cc: PostgreSQL Hackers , Alvaro Herrera Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! > I've thought about alternative solutions, too: how about getting a new sn= apshot every so often? > We don't really care about the liveness of the already-scanned data; the = snapshots used for RIC > are used only during the scan. C/RIC's relation's lock level means vacuum= can't run to clean up > dead line items, so as long as we only swap the backend's reported snapsh= ot (thus xmin) while > the scan is between pages we should be able to reduce the time C/RIC is t= he one backend > holding back cleanup of old tuples. Hm, it looks like an interesting idea! It may be more dangerous, but at least it feels much more elegant than an LP_DEAD-related way. Also, feels like we may apply this to both phases (first and the second sca= ns). The original patch (1) was helping only to the second one (after call to set_indexsafe_procflags). But for the first scan we allowed to do so only for non-unique indexes because of: > * The reason for doing that is to avoid > * bogus unique-index failures due to concurrent UPDATEs (we might see > * different versions of the same row as being valid when we pass over the= m, > * if we used HeapTupleSatisfiesVacuum). This leaves us with an index tha= t > * does not contain any tuples added to the table while we built the index= . Also, (1) was limited to indexes without expressions and predicates (2) because such may execute queries to other tables (sic!). One possible solution is to add some checks to make sure no user-defined functions are used. But as far as I understand, it affects only CIC for now and does not affect the ability to use the proposed technique (updating snapshot time to time). However, I think we need some more-less formal proof it is safe - it is really challenging to keep all the possible cases in the head. I=E2=80= =99ll try to do something here. Another possible issue may be caused by the new locking pattern - we will be required to wait for all transaction started before the ending of the phase to exit. [1]: https://postgr.es/m/20210115133858.GA18931@alvherre.pgsql [2]: https://www.postgresql.org/message-id/flat/CAAaqYe_tq_Mtd9tdeGDsgQh%2B= wMvouithAmcOXvCbLaH2PPGHvA%40mail.gmail.com#cbe3997b75c189c3713f243e25121c2= 0