Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5HAw-0001gq-8W for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jul 2021 00:30:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5HAv-000509-5u for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jul 2021 00:30:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5HAu-0004zx-O0 for pgsql-bugs@lists.postgresql.org; Mon, 19 Jul 2021 00:30:24 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5HAr-0004Pt-Vb for pgsql-bugs@lists.postgresql.org; Mon, 19 Jul 2021 00:30:23 +0000 Received: by mail-io1-xd31.google.com with SMTP id w22so9866590ioc.6 for ; Sun, 18 Jul 2021 17:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=jADA5yKDq96p3ilK71xKJuYFfvjcDrJ/eFgc027MQFc=; b=SLln8LO6WxAw+ABBYJZtOv1ye7t1/8MuGzw3I1M5V+LpmpnlRFODZpbnrdu4iWpK+b iY9mNX0kKxbqIYyTwZErxKEEReM3Q0Cs7p9XdsKXBuXMhj4wctjpaqwyf93AyxQ2sIgA /DVOcYj+TBhW9hX7qwFJxsyBVrCTxA03ru0QY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=jADA5yKDq96p3ilK71xKJuYFfvjcDrJ/eFgc027MQFc=; b=JoXlXpZ7D34oDT4dHjHMqHICxCqjpWeQI5ls/4gYOPOZppSS7B3dt8qPKizBBnoGLv PJQyqSHcbnMgt41M8eW372HMPNSZbg4CHVENZGFjUGS+gh+v2DHOBbGB2IYC48psHlg6 GlbKT/r3isa+cdUMLgqvUf6fOIMaK///VYcot6bvtBphwHWpMmg6tcGq/S8+CKHFVvO+ NxZQBpggNqLO63oYWUGWWRLu2Sr+m8/vlgEezZzSZm19wuoOCe2LlHjectfl3UNy+XYz kVZpDgdOIRds32cUPb+aDhmAl99EOykATA5ZwSpf0SABHXbLRnAHNNyfkLm3dwI40JHF qSVQ== X-Gm-Message-State: AOAM533NUZIsBPksbn2Q833CcY7kgj2ikFnRTy/q0zD+acPYQ5YLZYLm m4pVbXLBPfNn2iKYjfuY59jlMA== X-Google-Smtp-Source: ABdhPJxQtvQGcstyGjxs8p8vfwjrXMpHeNO/25yfvDnJBsA4/zOIG4s+xzsdr2IQ3Rdm4quTxdy3tA== X-Received: by 2002:a5d:8456:: with SMTP id w22mr17086468ior.63.1626654621056; Sun, 18 Jul 2021 17:30:21 -0700 (PDT) Received: from gust.leadboat.com ([172.243.183.102]) by smtp.gmail.com with ESMTPSA id b25sm9712095ios.36.2021.07.18.17.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 17:30:20 -0700 (PDT) Date: Sun, 18 Jul 2021 20:30:09 -0400 From: Noah Misch To: Andrey Borodin Cc: Michael Paquier , Tom Lane , pgsql-bugs@lists.postgresql.org Subject: Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data Message-ID: <20210719003009.GA931573@gust.leadboat.com> References: <2C1B82E7-B50C-470C-AE10-794ED2A7A64E@yandex-team.ru> <20210117072454.GA1709971@rfd.leadboat.com> <20210124022743.GA2270535@rfd.leadboat.com> <74C78048-70E8-4356-8F10-6370C37136C8@yandex-team.ru> <9C782C9D-D53E-4154-B910-46F062A9AE9B@yandex-team.ru> <01824242-AA92-4FE9-9BA7-AEBAFFEA3D0C@yandex-team.ru> <20210717201240.GA874334@gust.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Jul 18, 2021 at 10:17:28AM +0500, Andrey Borodin wrote: > > 18 июля 2021 г., в 01:12, Noah Misch написал(а): > > > > Suppose some transaction has a vxid but no xid. Shortly after > > GetLockConflicts(), it acquires an xid, modifies the table, and issues PREPARE > > TRANSACTION. Could that cause a corrupt index even with this diff? > > Firstly I've tried to stress things out. This little go program [0] easily reproduces corruption on patched code. By "patched code", you mean return_xids_with_vxids.diff applied to recent master, right? > Meanwhile vxid->xid->2px program does not [1] (both patched and unpatched). > > I think CIC does not care much about VXIDs at all. It's only important when real XID started: before GetLockConflicts() or after. CIC likes VXIDs because they're assigned early in the xact, before any catalog access. Consider the DefineIndex() step "wait until no running transaction could have the table open with the old list of indexes." ExecOpenIndices() can happen before AssignTransactionId(), so waiting on XIDs alone wouldn't suffice. To fix $SUBJECT, it sounds like we need a way to identify a transaction, usable as early as the transaction's first catalog access and remaining valid until COMMIT PREPARED finishes. We may initially see a transaction as having a VXID and no XID, then later need to wait for that transaction when it has entered prepared state, having an XID and no VXID. How might we achieve that?