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 1rLLpo-007TCm-Nj for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jan 2024 11:24:24 +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 1rLLpn-00C8B5-Dg for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jan 2024 11:24:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rLLpn-00C8Ax-39 for pgsql-hackers@lists.postgresql.org; Thu, 04 Jan 2024 11:24:23 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rLLpk-00Dgib-CH for pgsql-hackers@postgresql.org; Thu, 04 Jan 2024 11:24:21 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2cc7d2c1ff0so4637691fa.3 for ; Thu, 04 Jan 2024 03:24:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704367457; x=1704972257; 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=0ODNjg6uWwHHIjxWYiSsZsk+TBtqH/wJuTwch89027g=; b=nW4OdyBAZj1qR9i31OC/donfCUbjniiVmkahQNzQa0XgPMzeIZl6MTgqsKQArsyhSP A7DMOYlf2OLu7J7Y0x1ddbYUif5V/w1JMthSiPyKbMWiIUPzOOjrbFLmVjRVk3Hn2NJT CWiF3Y9Ui8BRRns4Te17WVY8pKEDr2O7JrY3jhWnrIVVsQS8BXrw2cYAssHqnng/oys0 +jpy7LA7k3NhE/5PtHntDuwhsVRLoi6tTV2vrmfcYzzbTfv8kamMIECAYrG0QIttzLAi rPvi1qLncf5jJnYAYBk5VvsnlHXUtTBF/SXnzt8EgzqONWbhuSYoo78+7dTn6qj36m+r ilFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704367457; x=1704972257; 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=0ODNjg6uWwHHIjxWYiSsZsk+TBtqH/wJuTwch89027g=; b=gtu1Pl3TYfLrY3ruX1NmPYv80ipNuFj0TH3Q1EcrjKnyEjjoXS9rTWpR4JEJM6LjDr eK6OXzexq9nPYWZAxoizk/tTtUzbVbsKJof/6LtHEkE86KPtezke7ZCHpNQ9t38Tuvxv 4A0lDRkDkk43/FnI+rUfFDOGvjLc+tmNUfdxpNgXLyrLnTYFw7G23SzT6hwv05TyADFI vkpXd9Jr/EBFfQYAawuemzSIfMOYwwYdeon6IpX5U0DT4BRfuWq/vjihtSd0290EyMfL gXBLhAVGFLphDRKrquqb3CIpNug7FjXfSk9uyEXMtSfmg4fSp9PmmxpZPdn9v0bKj2Aj fusQ== X-Gm-Message-State: AOJu0YyUDIPYSAnWKyT1p7rDyP9K31tY8GWOgqWp6kaQkigSQPBpzqnW kg7UP7SJ5b9oT/EMepxMy7pPdyaFm5SydOWZlQg= X-Google-Smtp-Source: AGHT+IHJm794bTfqdxkcPkAdD9o2x636yH4jqe/Zqj28UjVjlZv07W062MTVvZb8SVV4mhZ6tGz4ScwYNTg8L/31XB8= X-Received: by 2002:a2e:b8ce:0:b0:2cc:8dda:c96d with SMTP id s14-20020a2eb8ce000000b002cc8ddac96dmr256726ljp.28.1704367457387; Thu, 04 Jan 2024 03:24:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Thu, 4 Jan 2024 12:24:04 +0100 Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Michail Nikolaev Cc: PostgreSQL Hackers , Alvaro Herrera Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 25 Dec 2023 at 15:12, Michail Nikolaev wrote: > > Hello! > > It seems like the idea of "old" snapshot is still a valid one. > > > Should this deal with any potential XID wraparound, too? > > As far as I understand in our case, we are not affected by this in any way. > Vacuum in our table is not possible because of locking, so, nothing > may be frozen (see below). > In the case of super long index building, transactional limits will > stop new connections using current > regular infrastructure because it is based on relation data (but not > actual xmin of backends). > > > How does this behave when the newly inserted tuple's xmin gets frozen? > > This would be allowed to happen during heap page pruning, afaik - no > > rules that I know of which are against that - but it would create > > issues where normal snapshot visibility rules would indicate it > > visible to both snapshots regardless of whether it actually was > > visible to the older snapshot when that snapshot was created... > > As I can see, heap_page_prune never freezes any tuples. > In the case of regular vacuum, it used this way: call heap_page_prune > and then call heap_prepare_freeze_tuple and then > heap_freeze_execute_prepared. Correct, but there are changes being discussed where we would freeze tuples during pruning as well [0], which would invalidate that implementation detail. And, if I had to choose between improved opportunistic freezing and improved R/CIC, I'd probably choose improved freezing over R/CIC. As an alternative, we _could_ keep track of concurrent index inserts using a dummy index (with the same predicate) which only holds the TIDs of the inserted tuples. We'd keep it as an empty index in phase 1, and every time we reset the visibility snapshot we now only need to scan that index to know what tuples were concurrently inserted. This should have a significantly lower IO overhead than repeated full index bulkdelete scans for the new index in the second table scan phase of R/CIC. However, in a worst case it could still require another O(tablesize) of storage. Kind regards, Matthias van de Meent Neon (https://neon.tech) [0] https://www.postgresql.org/message-id/CAAKRu_a+g2oe6aHJCbibFtNFiy2aib4E31X9QYJ_qKjxZmZQEg@mail.gmail.com