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 1rFuYT-00CkNY-H9 for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Dec 2023 11:16:01 +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 1rFuXR-00BdEn-CG for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Dec 2023 11:14:57 +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 1rFuXQ-00BdEf-WB for pgsql-hackers@lists.postgresql.org; Wed, 20 Dec 2023 11:14:57 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rFuXJ-00Cx05-RZ for pgsql-hackers@postgresql.org; Wed, 20 Dec 2023 11:14:56 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2cc7ba7d12eso23462331fa.3 for ; Wed, 20 Dec 2023 03:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703070889; x=1703675689; 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=3NXNVjefqWdwUgOp4MBI4QsSqzdEROIjM3utgfer/uc=; b=RholoyXseILsnGMHWu74l1rYpJego2QrDgADSluTfhdqLGwAfSWnNQV5e0ALLKh4ZK RSfGAt9vRE6xLQPnSxqeeK38xBVLmWnBe1SleYSDsvIau9ky1GPSvmPhuWFji6v6mdZ9 ji6fTUd/fORDcfMgncZY7m5bZ62sIrd+Yoa08PfwqpYrZSy+FcsChOZNC1+jYMblIWEQ XTvHWV2a0DqiygYo/HGhMb3t5ofiOtI258ocAMZgvyaN3stsTuRnVriQECP003Lmoqki 6ENQrGCN6jZm49VJ/Flo/jwk3pC9yhD75yZ9eE4U5FBCNGm9YMyAmhOEOVDhQWSdnu92 OnaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703070889; x=1703675689; 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=3NXNVjefqWdwUgOp4MBI4QsSqzdEROIjM3utgfer/uc=; b=g+worpXs4wrLYIk1L6QVInGonTdts9+QFkBHqexmnGXc45JP7P4hvk+jl4NpMTPZgZ T1OcTh7ObRQ2Hrc+W8sNa2366KP4XZ6u3Uef932lhygJoOe2b+TKG1+ACq78n9PnIF6B s84ZLXrCQJ1B09ug26OElNIV/Kkpedw7Jq6ryiXQ/3OVjhEnh7aib58FdwR/G8Z8HnKG BVEqyVQztLhAt1gHEnRCdXRPy8jOOC8zV0HUnfDj5qZ+yDzLBqEh5UaTDZPntFOpS/kp 8CmKsic25fnvKprFsF/0ivss8x7eMImSWZ9E2ZJXcWjnlUupbfc2kQo3nspN9jG/Z9WB 2+ag== X-Gm-Message-State: AOJu0YxpZ2HxJFC5tKaVzNlOw2EiSy2Lfl5NEYe/N9T9YYm95FT5fc6n xJ0RSFVFRGmFKuZ2k6Q6LrFAWaFx1b8IHzrqbrdM4dqLWcQ= X-Google-Smtp-Source: AGHT+IEOt4kVu2K/sdjSg+VgY1TtgnE7o1uxygTFSKC92tASF3PSoqcBgvPYRyC2J6Zhx2g5JqVOHgowraO7Mka/kBk= X-Received: by 2002:a2e:850b:0:b0:2cc:7349:8ea with SMTP id j11-20020a2e850b000000b002cc734908eamr1841174lji.59.1703070888346; Wed, 20 Dec 2023 03:14:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Wed, 20 Dec 2023 12:14:32 +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 Wed, 20 Dec 2023 at 10:56, Michail Nikolaev wrote: > > Note that the use of such expressions would be a violation of the > > function's definition; it would depend on data from other tables which > > makes the function behave like a STABLE function, as opposed to the > > IMMUTABLE that is required for index expressions. So, I don't think we > > should specially care about being correct for incorrectly marked > > function definitions. > > Yes, but such cases could probably cause crashes also... > So, I think it is better to check them for custom functions. But I > still not sure - > if such limitations still required for proposed optimization or not. I think contents could be inconsistent, but not more inconsistent than if the index was filled across multiple transactions using inserts. Either way I don't see it breaking more things that are not already broken in that way in other places - at most it will introduce another path that exposes the broken state caused by mislabeled functions. > > 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? > HeapTupleSatisfiesHistoricMVCC That function has this comment marker: "Only usable on tuples from catalog tables!" Is that correct even for this? Should this deal with any potential XID wraparound, too? 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... Either way, "Historic snapshot" isn't something I've worked with before, so that goes onto my "figure out how it works" pile. Kind regards, Matthias van de Meent Neon (https://neon.tech)