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 1m5xcg-00046o-Tn for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Jul 2021 21:49:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m5xcf-00020A-Kw for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Jul 2021 21:49:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5xcf-000202-6w for pgsql-bugs@lists.postgresql.org; Tue, 20 Jul 2021 21:49:53 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m5xcc-0000kl-QQ for pgsql-bugs@lists.postgresql.org; Tue, 20 Jul 2021 21:49:52 +0000 Received: by mail-io1-xd30.google.com with SMTP id z17so110843iog.12 for ; Tue, 20 Jul 2021 14:49:50 -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=vof1+l+DkBX4x51qn3hUlESVuvHkFPMh+WXIroZKcIs=; b=I0iX+MObQxaZ8nmrWcRkdkPFxcfTctKzs4t0ZqxJrEPtCmlty/x5t9fUGJC0Prmi5r oRmgF6Ok1JBFqSnui6OpYkQS3j3vXuCRqMzDrl20F8yqXdZihnADIZr8uZI49L8SL3jf fG3iYmQxV4uc961PqW8QePWOWURCFMnLaWLvE= 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=vof1+l+DkBX4x51qn3hUlESVuvHkFPMh+WXIroZKcIs=; b=PcNZBtNRqLFh0+Df5S5U5eUm4Nq6RnBgbPIBzAEKnpWJyDIAE1oYwr5BjQotVMlHuC UG3QvVzqvckrSaxiwv8qCzvmzLDIjc3joYM7uOzCR254I54m/ul/1fvlUWhYksoIYZrt ezJDv8/ApcNVRTjl1w0pjDI0JW8oeiv3tGFaPT2Gbsg+Qp6HW/bLWkdTQsOoADMeI+dC 31LCJRK3ER/IET6nbI4aG6vyUDTm01JXcHsva4S+TgSg7W6U6LuB+Eq+jB2ZcDCAg6zv 9Z+LpodzqZeOfFaXbkEtXqDHtaNxKS+dwIqruXLC/G6RkM6SKTUpjvLvwjPdNfhJO2bq 9qqQ== X-Gm-Message-State: AOAM532mN3mBb991CExJeQE2ie2D8wwmBoih/+VPAWqipk2SwE6SifWo DlPUUoNifn3Zo4XtBXbpTaLZeA== X-Google-Smtp-Source: ABdhPJxHkXKsmHAiWp14cCrbtabB8R4sSHQU5VGeFB6JluX/1aINalomoMamlJddb1YJXzeP23GDUw== X-Received: by 2002:a6b:b795:: with SMTP id h143mr24489776iof.74.1626817788655; Tue, 20 Jul 2021 14:49:48 -0700 (PDT) Received: from gust.leadboat.com ([172.243.183.102]) by smtp.gmail.com with ESMTPSA id t24sm13382671ioh.24.2021.07.20.14.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 14:49:48 -0700 (PDT) Date: Tue, 20 Jul 2021 17:49:36 -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: <20210720214936.GA1040253@gust.leadboat.com> References: <20210719181005.GB972361@gust.leadboat.com> <1727EC55-0709-4E06-91C9-212682A134C7@yandex-team.ru> 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 Wed, Jul 21, 2021 at 12:38:25AM +0500, Andrey Borodin wrote: > > 19 июля 2021 г., в 23:41, Andrey Borodin написал(а): > > > 19 июля 2021 г., в 23:10, Noah Misch написал(а): > > > On Mon, Jul 19, 2021 at 12:10:52PM +0500, Andrey Borodin wrote: > > >>>> 19 июля 2021 г., в 05:30, Noah Misch написал(а): > > >>> > > >>> 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? > > >> > > >> PFA draft with vxid->xid mapping and subsequent wait for it. The patch, obviously, lacks a ton of comments explaining what is going on. > > >> We write actual VXID into dummy proc entries of prepared xact. > > >> When we wait for vxid we try to convert it to xid through real proc entry. If we cannot do so - we lookup in shared 2pc state. If vxid is not there - it means it is already gone and there's nothing to wait. > > > > > > When the system reuses BackendId values, it reuses VXID values. In the > > > general case, two prepared transactions could exist simultaneously with the > > > same BackendId+LocalTransactionId. Hmm. It could be okay to have a small > > > probability that CIC waits on more transactions than necessary. Suppose we > > > have three PGPROC entries with the same VXID, two prepared transactions and > > > one regular transaction. Waiting for all three could be tolerable, though > > > avoiding that would be nice. Should we follow transactions differently to > > > avoid that? > > > > We don’t have to wait for regular Xid in this case at all. Because it would be finished with VXID. I don't understand those two sentences. Could you write more? > > We are looking for transaction that was only VXID during GetLockConflicts(). In conflicts array we may have each VXID only once. > > Other 2PCs with same VXID may be older or newer than target 2PC. > > Older 2PCs must be with XID in conflicts array. So we might wait for all 2PC with known XIDs. Then for each ambiguous VXID->XID mapping choose oldest XID. > Unfortunately, this is just wrong. Older 2PC with same VXID don't have to be in conflicts array. They might be of some other unrelated 2PC working with different relations. I agree. Would it work to do the following sequence in WaitForLockers()? 1. In GetLockConflicts(), record a list of conflicting XIDs. Also record a list of conflicting LXIDs having no XID. 2. Wait on all LXIDs recorded in (1). They have either ended or converted to prepared transactions. 3. Inner-join the present list of prepared transactions with the list of LXIDs from (1). Record the XIDs of matched entries. 4. Wait on all XIDs recorded in (1) and (3). While that may wait on some prepared XIDs needlessly, it can't degrade into persistent starvation. We could reduce the chance of a needless XID wait by remembering the list of old prepared XIDs before (1) and not adding any of those remembered, old XIDs in (3). That last bit probably would be unjustified complexity, but maybe not.