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 1m1uQa-0000ea-U4 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jul 2021 17:36:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m1uQX-0003fU-Ms for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jul 2021 17:36:37 +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 1m1uQX-0003fL-Ah for pgsql-hackers@lists.postgresql.org; Fri, 09 Jul 2021 17:36:37 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m1uQO-0004gE-R5 for pgsql-hackers@postgresql.org; Fri, 09 Jul 2021 17:36:36 +0000 Received: by mail-ed1-x52b.google.com with SMTP id l2so14976451edt.1 for ; Fri, 09 Jul 2021 10:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Trla2X4hXuQJngSgcvaPYteHpIuFo7HdYUo5BxPFcVE=; b=Gf8rJ8QCpnemXz9QzUqkcfOz2ZjSkGwBv4Y3wyKVk3KFshenVDxMqpdSFAuJ77cUCb E9O5C+flycuKt/1U/IfyPm/LrF4bW1LRyGyJfNz2DsqOyqET77o6fkjjlLu/nY4bmlI7 NXZNrksTaMsiR7Lp75Ls14iI9XXrKzBERqhY4L99kBzt89oQDmVGkW/Y+SuJeqhhgSsD irRDve8cjH9pB9uz05wSruINRTIbmyZiGWtfwHYVbQ08K5phjgPhPEibvMcOpaqm6kv8 SjiH4i9wc2wO9UeJsmeiXHqwlsTX1HlACWya08tCP+04mYqVFRkx7EyW1EPGAC3tIzdJ wZpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Trla2X4hXuQJngSgcvaPYteHpIuFo7HdYUo5BxPFcVE=; b=bqQsSH3c0Mc0nBuGIiRJWmXwUQ0cTjjn1bqDnVKG5jKK74QGVaVEvXNFZzg+6Kvyln segAoFFDu0Ijd6IkWOEjZl/QKD9TosbmVapS4r1eRRogMtGJTTWLrwUnYFCqrBEeVTtJ WQR3iUOxNyWlH+xk0Jcd4USeM0eytkJd/S9W0Z7PUml8XGIh0cmUKJmUfP0bWUhAMxIE UO8EpwEeDOKuwx5vP0NZKvUpZ7Ccln2dCBRo1bQB9Bk3accaR9zqjHaysSTDGBa2XJsu g4TAGphUiwLSCcJ0+uws5K+ljZU1TmE75vGBZNxAwEDkn5s/rCZl/H49RGJ1IP/rKzcI 4rBw== X-Gm-Message-State: AOAM5337axLy56nYZ99+0ifahPskWcqU3A71F9ES3gvVDhBRREeKOhVg pm49yZEmueXv1D3/ZpJUgI1ZLplvUfNAuy6pZjiJ5OBOZ2I1jiiMG5J2+7kskoL21vjtq6/iV8z t85DloyIGyvTfpT8kLJrhdYZv2izqCqCC2olm1hpxRqbiJjbmbJQj6Iimb7GQp+20gHM8RHkUXv SRVQE/wpsdVfJpZDb0WDHab8MfAev0pAIne5fMCSCZkPc9LTYc0XL0TPsT3I59/FJ3/sFZc0b0t XTlbpqq++AbOMv2Ra+yk1Q6VMkyD6yRAUbFGQ== X-Google-Smtp-Source: ABdhPJysBX6BAQJrKBopIt1AsTZ2OdyuJLgspYXuBXZaEzLHk+H9FFHyX6mXtgXDbCaGqc8tngzXDA== X-Received: by 2002:a05:6402:53:: with SMTP id f19mr48402901edu.200.1625852186178; Fri, 09 Jul 2021 10:36:26 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id x1sm3172425edd.25.2021.07.09.10.36.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Jul 2021 10:36:25 -0700 (PDT) Subject: Re: Parallel scan with SubTransGetTopmostTransaction assert coredump To: Pavel Borisov , Greg Nancarrow , Robert Haas Cc: Maxim Orlov , Michael Paquier , Pengchengliu , Andres Freund , PostgreSQL-development References: <000901d74b84$fa262890$ee7279b0$@tju.edu.cn> <000801d74d16$150494c0$3f0dbe40$@tju.edu.cn> <09788181118f7bd8000d3bb097e0720f@postgrespro.ru> <08ae178b309c617a9701cbc7ed8a98f0@postgrespro.ru> From: Tomas Vondra Message-ID: <5d730e4e-4fb2-bd5c-f6be-488ad692ed3a@enterprisedb.com> Date: Fri, 9 Jul 2021 19:36:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I took a quick look on this - I'm no expert in the details of snapshots, so take my comments with a grain of salt. AFAICS both Greg Nancarrow and Pavel Borisov are kinda right. I think Greg is right the v3 patch does not seem like the right (or correct) solution, for a couple reasons: 1) It fixes the symptoms, not the cause. If we set TransactionXmin to a bogus value, this only fixes it locally in SubTransGetTopmostTransaction but I'd be surprised if other places did not have the same issue. 2) The xid/TransactionXmin comparison in the v2 fix: xid = xid > TransactionXmin ? xid : TransactionXmin; seems broken, because it compares the XIDs directly, but that's not going to work after generating enough transactions. 3) But even if this uses TransactionIdFollowsOrEquals, it seems very strange because the "xid" comes from XidInMVCCSnapshot(HeapTupleHeaderGetRawXmin(tuple), snapshot)) i.e. it's the raw xmin from the tuple, so why should we be setting it to TransactionXmin? That seems pretty strange, TBH. So yeah, I think this is due to confusion with two snapshots and failing to consider both of them when calculating TransactionXmin. But I think removing one of the snapshots (as the v2 does it) is rather strange too. I very much doubt having both the transaction and active snapshots in the parallel worker is not intentional, and Pavel may very well be right this breaks isolation levels that use the xact snapshot (i.e. REPEATABLE READ and SERIALIZABLE). I haven't checked, though. So I think we need to keep both snapshots, but fix TransactionXmin to consider both of them - I suppose ParallelWorkerMain could simply look at the two snapshots, and use the minimum. Which is what [1] (already linked by Pavel) talks about, although that's related to concerns about one of the processes dying, which is not what's happening here. I'm wondering what consequences this may have on production systems, though. We've only seen this failing because of the assert, so what happens when the build has asserts disabled? Looking at SubTransGetTopmostTransaction, it seems the while loop ends immediately (because it's pretty much the opposite of the assert), so we just return the "xid" as topmost XID. But will that produce incorrect query results, or what? regards [1] https://www.postgresql.org/message-id/20150208002027.GH9201%40alap3.anarazel.de -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company