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 1m6GRj-0008Rx-D3 for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Jul 2021 17:55:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6GRi-0005RY-0g for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Jul 2021 17:55:50 +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 1m6GRh-0005RP-Is for pgsql-bugs@lists.postgresql.org; Wed, 21 Jul 2021 17:55:49 +0000 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m6GRb-00013N-07 for pgsql-bugs@lists.postgresql.org; Wed, 21 Jul 2021 17:55:48 +0000 Received: by mail-io1-xd2e.google.com with SMTP id l5so3300121iok.7 for ; Wed, 21 Jul 2021 10:55:42 -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=Pv+8a5yiQDBwZgjvR4F89bBNIM0TsY0A0Frq6bcZtF0=; b=AkrPu+u/yrN685psZdtZpibw5GTboxdaNc/IFcY8LoFQi18k5DYc8rli7v0txgh2Km GYxtXHUfX0TF2SoREVg2KxK9BpWWuH9SFYaLwcB1Zq0Uygt0W1mt2bgQ7BGrdb9tXNso QIzBPMnP9PaWBJvghcIYSYvfihz2z18D/6/vg= 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=Pv+8a5yiQDBwZgjvR4F89bBNIM0TsY0A0Frq6bcZtF0=; b=FrhplFGvPMn6G3I/8f8dPoWQl+aJl2voYEV+Rynb2aAaw73m8HaueUfsuTrEOCEmP/ 2rCKcIKxr+cfxPjGpa65OI6yjqNdHSgp3UhH7wpFVkcKTjLdAWeGg/NyT2+XPJKJG2al p8adUmduU+t60EAoXhL4F9pn1LFc9Rw+dym+JmZx0JFzhA5DGZ9mno6zV7LVWkOXV0I2 eiyO8EFPDulN6ZIiKBic8OVTlEr3JXXR79TVRHU1kZR2/5Gxa1IiA+BEUTh+/ZNF5txT /7iLkJ9T9BxnGReqrdXkOQS8k8Rxl2Ti4dfvN7tjL+yKtUHAfK07rfAmt+HmUMmSzuQ8 mvxg== X-Gm-Message-State: AOAM532lczkiM8pRO2Wgm9BbHG8A7/y6SZfEqxEgSCGLVV5pamVmnm1P //gCgoOwImNyK9UZFaQD4o+e/w== X-Google-Smtp-Source: ABdhPJwAfTf6rxP5BbphayJPWASsMX+uq1A697SE7xU4n+Jx7Lld7JmVbt5avvhn5wxWSY3VS7RH4w== X-Received: by 2002:a5d:938a:: with SMTP id c10mr11620655iol.0.1626890142164; Wed, 21 Jul 2021 10:55:42 -0700 (PDT) Received: from gust.leadboat.com ([172.243.183.102]) by smtp.gmail.com with ESMTPSA id r14sm13156656ilm.77.2021.07.21.10.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 10:55:41 -0700 (PDT) Date: Wed, 21 Jul 2021 13:55:30 -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: <20210721175530.GA1090577@gust.leadboat.com> References: <20210719181005.GB972361@gust.leadboat.com> <1727EC55-0709-4E06-91C9-212682A134C7@yandex-team.ru> <20210720214936.GA1040253@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 Wed, Jul 21, 2021 at 01:13:08PM +0500, Andrey Borodin wrote: > > 21 июля 2021 г., в 02:49, Noah Misch написал(а): > > 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 написал(а): > >>>> 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? > Suppose we have a VXID conflicting with reindexed relation lock, and have a PGPROC with regular Xid (not 2PC) for this VXID. > We do not need to return this xid from TwoPhaseGetXidByVXid() for extra wait. This situation is covered by normal vxid handling in VirtualXactLock(). > + /* Save the xid to test if transaction coverted to 2pc later */ > + xid = proc->xid; Got it. > > 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. > I think this protocol is equivalent to waiting on all Xids with VXid. > I consider this protocol safe. FPA implementation. > Patch 0001 is intact version of previous patch. > There are two additions: > 1. Prefer xids to vxids in GetLockConflicts() > 2. Wait on all 2PCs with given VXid. These drafts use reasonable concepts. Would you develop them into a ready-to-commit patch? You may be able to translate your probabilistic test procedures from https://gist.github.com/x4m/8b6025995eedf29bf588727375014dfc into something like the src/bin/pgbench/t/001_pgbench_with_server.pl test of pg_enum_oid_index.