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 1rFzHJ-00D4oV-5A for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Dec 2023 16:18:37 +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 1rFzHH-00ET30-Aj for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Dec 2023 16:18:35 +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 1rFzHH-00ET2n-0n for pgsql-hackers@lists.postgresql.org; Wed, 20 Dec 2023 16:18:35 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rFzHE-00BM8B-Jb for pgsql-hackers@postgresql.org; Wed, 20 Dec 2023 16:18:33 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a2339262835so484150166b.3 for ; Wed, 20 Dec 2023 08:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703089111; x=1703693911; 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=xli7/hq3/tnrkUmpvSrN8mGNfrDe3kEZcMGKVTEboOg=; b=Ug9ye/hvOGW26rk6QZAoneGf/wRQR5M6SO1i3eJlE2drQGo7HBGLXejSQLBoLiqtpe TgR8o+k38AVokMKEQsYqegvLIE63BKu9UA5CUeMGg+2XyF6HWu7PPezsg+FMsy8++uTM Us9h++1oHER3wshKouXJCeOtkKBMTwmuPqqWsNAcla645HyYrXCxU7J7wwQZOQRy6Dam keSNvPgfz6e4n1mpCF72oOLf0PPeZ72uyUoag0WZJVKY3EO4RbZWX9feEnHxsBQsXWx9 aYQSPASDSkPX8+wijD97wpQM1n++QrMXNwRU9qAjdDHmj7oa4ULw203JnPCTvpLsd3yy pZ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703089111; x=1703693911; 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=xli7/hq3/tnrkUmpvSrN8mGNfrDe3kEZcMGKVTEboOg=; b=fz+dY1FOrHjhyFMZbqNvSnCogC0ZfUomLozbF2mFhN92EUkyKNfDn4UG6QGmEuJF/A HFD+LId0B44088Tu3qIop45keJli+y1o6hirrT81p3FCz+jgVxn03DFR3gTbBb+Fju5T avyFj2EpKzG7dcEUK6FlJ54rL2vkF7YHICHFwkQFgJP+ciSnmP/P0YwTXERLt6GDrhy0 YE6u7Z2pyI7Yib1hzJjT99t7CMy/nbnIiE/xDC8ys/5U+f9HymDfKJrAugwYMy8PUrSb W4mDhXbrSPwyqrI1eJgsr+ZQF7UuZZzEzEegd+vbg5SGal4xrzonOF90nFimhLS1BpxZ C/+g== X-Gm-Message-State: AOJu0Yx257nbOqHUFNMPXc1Gztv7aITsG6iMjaLAFdxGCjTrm4Vb7EgE ZeEW4kjh3VvUzpOvkNJtpK+mqRo6iqPldAMjeZf/PVn1juE= X-Google-Smtp-Source: AGHT+IFNOKUxgJW43ug0T6WOMItSuN1jcuCZi6IFZVDt82/IpN9HZBIWSGhIehLwI2n1pkV70prszsXaDGHM0W7t2CA= X-Received: by 2002:a17:907:7246:b0:a26:9977:e328 with SMTP id ds6-20020a170907724600b00a269977e328mr549180ejc.17.1703089110788; Wed, 20 Dec 2023 08:18:30 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Wed, 20 Dec 2023 17:18:18 +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! > 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? Yes, exactly. >> HeapTupleSatisfiesHistoricMVCC > That function has this comment marker: > "Only usable on tuples from catalog tables!" > Is that correct even for this? Yeah, we just need HeapTupleSatisfiesVisibility (which calls HeapTupleSatisfiesMVCC) instead. > Should this deal with any potential XID wraparound, too? Yeah, looks like we should care about such case somehow. Possible options here: 1) Skip vac_truncate_clog while CIC is running. In fact, I think it's not that much worse than the current state - datfrozenxid is still updated in the catalog and will be considered the next time vac_update_datfrozenxid is called (the next VACCUM on any table). 2) Delay vac_truncate_clog while CIC is running. In such a case, if it was skipped, we will need to re-run it using the index builds backend later. 3) Wait for 64-bit xids :) 4) Any ideas? In addition, for the first and second options, we need logic to cancel the second phase in the case of ForceTransactionIdLimitUpdate. But maybe I'm missing something and the tuples may be frozen, ignoring the set datfrozenxid values (over some horizon calculated at runtime based on the xmin 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... Yes, good catch. Assuming we have somehow prevented vac_truncate_clog from occurring during CIC, we can leave frozen and potentially frozen (xminfrozenXID (may not be frozen) * visible by snapshot second phase: * frozen * xmin>frozenXID (may be frozen) * not in the index summary * visible by "old" snapshot You might also think =E2=80=93 why is the first stage needed at all? Just u= se batch processing during initial index building? Best regards, Mikhail.