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 1rVZaQ-000609-8U for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 16:06:46 +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 1rVZaP-005pug-9R for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 16:06: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 1rVZaO-005puY-WD for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2024 16:06:45 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rVZaM-004vT7-LF for pgsql-hackers@postgresql.org; Thu, 01 Feb 2024 16:06:44 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a35e65df2d8so142493366b.0 for ; Thu, 01 Feb 2024 08:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706803601; x=1707408401; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mZXk7Y/uqZyDgO6jjLw6DTrydC3Rlh7laLYjHJ5F9LI=; b=BG86LUw9incPLv+qlRjo+93vrwZNxMuefjup8WvKyf8qBnAU78tHycY4+deEeqy1KS Pxmj7dkPAKxNoNm18CjRZNrsaYpbInFm9S6W07BHddgbkS7f8xvxJJaA4kFSOderu1fk AHQc3yJxdZYk+sqSLS6NkxIfEhU4QE4Sxa0RBCVAO8Dg0NJWlAQC+Zt3L084Gp+nb55R McsspMWxijv4r3hu17ia5lxwkfBsfLi6jrr9z0wV2/Gp0BKEKra/Rk8WCAALynLRKpqE EsD+KlnsirN6pXh+/8TBcvfvE1x+GgE/Q5eMipPpqbcvVI6/hbPM41UY7b8P6RpqbUnU m7uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706803601; x=1707408401; h=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=mZXk7Y/uqZyDgO6jjLw6DTrydC3Rlh7laLYjHJ5F9LI=; b=NiHx8cmGH6TE1uGJKVCKthxwCoov7TvOs93lxO7XoVCO4RNI5BZXp80lhcPE8dR7Am /HiY/QRrHpMV6jKujtDFagv5csuIT76VZwV5RB0yOG5YO1ovnK+faXza5a0d0oq1vFij KE8Tj1WlR93CPaC4v8FlppSfP3glAgte3ztL1UQ6oAXgeOV70g6QP9ipPglks8f1NmGB Z8m/Eeu83zMZhjP+V7NtwLRSQ6Ve0ii22adfS7BJZTzcRtVbO+0YLTnOGo9/Yemlq8M7 kYzxU2K6uS+FsWXddbWWxmNUtQlMylBorTyXEZ9Z0CTZ2qQZ2yedrhzKcDBiRgNHuzKz hL9A== X-Gm-Message-State: AOJu0YwhPMvl8qNAy2GHTSBdg/is1zjtROqF4PAVa3Mf01RqBvi7lj// 5kbTIoZ2nOZno0hbik9Hy+wNdBeUOGJXNHBdqdVWX7o4Gbq63+72SYjr8qr1cjEttg6N36/amqI 19fur7+zX8iGSvEKwHbx2idtMO2mP6yrny/U= X-Google-Smtp-Source: AGHT+IGd3ZNXWt2nZi/nLFLdpbP/7MtmOOOXYhGmqf8htX0aP0QGafy7QfGH6WEfG2fO3wjtWPjBEU7VHRWULSsvZZA= X-Received: by 2002:a17:906:d114:b0:a35:e26c:e80a with SMTP id b20-20020a170906d11400b00a35e26ce80amr3912715ejz.3.1706803601154; Thu, 01 Feb 2024 08:06:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Thu, 1 Feb 2024 17:06:28 +0100 Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Melanie Plageman Cc: PostgreSQL Hackers , Alvaro Herrera , Matthias van de Meent Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > > > I just realised there is one issue with this design: We can't cheaply > > > reset the snapshot during the second table scan: > > > It is critically important that the second scan of R/CIC uses an index > > > contents summary (made with index_bulk_delete) that was created while > > > the current snapshot was already registered. > > > > > So, the "reset the snapshot every so often" trick cannot be applied in > > > phase 3 (the rescan), or we'd have to do an index_bulk_delete call > > > every time we reset the snapshot. Rescanning might be worth the cost > > > (e.g. when using BRIN), but that is very unlikely. > > > > Hm, I think it is still possible. We could just manually recheck the > > tuples we see > > to the snapshot currently used for the scan. If an "old" snapshot can see > > the tuple also (HeapTupleSatisfiesHistoricMVCC) then search for it in the > > index summary. > That's an interesting method. > > How would this deal with tuples not visible to the old snapshot? > Presumably we can assume they're newer than that snapshot (the old > snapshot didn't have it, but the new one does, so it's committed after > the old snapshot, making them newer), so that backend must have > inserted it into the index already, right? I made a draft of the patch and this idea is not working. The problem is generally the same: * reference snapshot sees tuple X * reference snapshot is used to create index summary (but there is no tuple X in the index summary) * tuple X is updated to Y creating a HOT-chain * we started scan with new temporary snapshot (it sees Y, X is too old for it) * tuple X is pruned from HOT-chain because it is not protected by any snapshot * we see tuple Y in the scan with temporary snapshot * it is not in the index summary - so, we need to check if reference snapshot can see it * there is no way to understand if the reference snapshot was able to see tuple X - because we need the full HOT chain (with X tuple) for that Best regards, Michail.