Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMEBV-0002bu-49 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 May 2019 16:03:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMEBT-0007eW-TH for pgsql-hackers@arkaria.postgresql.org; Thu, 02 May 2019 16:03:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMEBT-0007bn-GD for pgsql-hackers@lists.postgresql.org; Thu, 02 May 2019 16:03:43 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMEBQ-0000js-FH for pgsql-hackers@postgresql.org; Thu, 02 May 2019 16:03:43 +0000 Received: by mail-qt1-x844.google.com with SMTP id d13so3116399qth.5 for ; Thu, 02 May 2019 09:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=LwF+iZQRPzrKZ1JhKhOqXLbApN51h7L5hdriwe4tD3s=; b=PlStgRPW5ZmYykacNGLH1pmC250oMWgBakRA2TXzWqkktWFwmETa2B4SqPIre22AUp Zsd438FQ1aw9jpoElC8cYRaBECkNRzEESvJQIAHwPqTUzLwhkx/RFhZPTe5pU7U04GRZ fXs/iWVL5SOFoZriDQktu7rjO9724f8MmakzUFkgqP4JnHrje2P2ZnHjTuZjtFCrBdkt d0fGUCG+2Z1yJ5rTOprbAM9jn96347V6P5TziUzhGneHGPq/vavicyUT2oBVJ5URjsYT sgZxF4HVM9g9oB1zPYlmDFGN0QCcbhJ8I33LnU4uo1o4uUr4zW04TsncniSPoE6T5NSw CdpA== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=LwF+iZQRPzrKZ1JhKhOqXLbApN51h7L5hdriwe4tD3s=; b=ul/Ue2u5ek/Xtcpd3N/+5UTbWqO+aaRzODPrOIOSCI9SnYJtKGqIioNNnuXRCX207B xVbsK9/hBc8IwQVqoioipkurRc/znYT4BPeuTllVQ17GrcNovRo8cDSu7BXHjGUs8NS+ 5e+G5IO7rFJnG40d1PUXh+6nG6WKCZeDILvSCDNRTUKQToLXK5n5YMbJbkG2Sc0SN8In xznLwRgZDXq3LSUDfpYq3W+xN5R7IlvcsEuFmNTJCzKlgsMeu5ycwWvvbEYNaUfEXnOS qm7q5d91e5IubadGB8QEqhfUrKeX90g6w0awaLWQvNm4cxHUraiMja58p1OesIUxiS/s 2DSw== X-Gm-Message-State: APjAAAVPU7e4LPxVnVOgzsb7+Dzdm51Q3AeidGP2bgQ5fPwIElc7mwL6 gIlmpCAOGLT6R8MFeY8jrASFpw== X-Google-Smtp-Source: APXvYqySWElWXWvIRSWOEj4mWZ1OkvCgCuxsqqTuqod6GdDpz12nXmyhmywu2ttmOLKEYYZcOak/xA== X-Received: by 2002:a0c:b0a5:: with SMTP id o34mr3642685qvc.42.1556813018815; Thu, 02 May 2019 09:03:38 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id 23sm597970qkf.94.2019.05.02.09.03.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 09:03:38 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 8F00D120C22; Thu, 2 May 2019 12:03:35 -0400 (-04) Date: Thu, 2 May 2019 12:03:35 -0400 From: Alvaro Herrera To: Andres Freund Cc: Tom Lane , Robert Haas , Masahiko Sawada , Kyotaro HORIGUCHI , "Bossart, Nathan" , PostgreSQL-development Subject: Re: New vacuum option to do only freezing Message-ID: <20190502160335.GA17452@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6c2NcOVqGQ03X4Wi" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190501153637.nyleiq67w4lvbo46@alap3.anarazel.de> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-May-01, Andres Freund wrote: > Alvaro, could we perhaps clean this up a bit? This is pretty confusing > looking. I think this probably could just be changed to > > bool xmin_frozen = false; > > xid = HeapTupleHeaderGetXmin(tuple); > > if (xid == FrozenTransactionId) > xmin_frozen = true; > else if (TransactionIdIsNormal(xid)) > > or somesuch. There's no need to check for > HeapTupleHeaderXminFrozen(tuple) etc, because HeapTupleHeaderGetXmin() > already does so - and if it didn't, the issue Tom points out would be > problematic. Ah, yeah, that's simpler. I would like to introduce a couple of very minor changes to the proposed style, per the attached. * don't initialize xmin_frozen at all; rather, only set its value to the correct one when we have determined what it is. Doing premature initialization is what led to some of those old bugs, so I prefer not to do it. * Handle the BootstrapXid and InvalidXid cases explicitly, by setting xmin_frozen to true when xmin is not normal. After all, those XID values do not need any freezing. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --6c2NcOVqGQ03X4Wi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-heap_prepare_freeze_tuple-Simplify-coding.patch" From 1cca0581655614703b020facbbf8d64b442f95be Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 2 May 2019 11:50:18 -0400 Subject: [PATCH] heap_prepare_freeze_tuple: Simplify coding --- src/backend/access/heap/heapam.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index a05b6a07ad0..d6ceb8fd4a4 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -6108,9 +6108,9 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, /* Process xmin */ xid = HeapTupleHeaderGetXmin(tuple); - xmin_frozen = ((xid == FrozenTransactionId) || - HeapTupleHeaderXminFrozen(tuple)); - if (TransactionIdIsNormal(xid)) + if (!TransactionIdIsNormal(xid)) + xmin_frozen = true; + else { if (TransactionIdPrecedes(xid, relfrozenxid)) ereport(ERROR, @@ -6118,7 +6118,8 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, errmsg_internal("found xmin %u from before relfrozenxid %u", xid, relfrozenxid))); - if (TransactionIdPrecedes(xid, cutoff_xid)) + xmin_frozen = TransactionIdPrecedes(xid, cutoff_xid); + if (xmin_frozen) { if (!TransactionIdDidCommit(xid)) ereport(ERROR, @@ -6128,7 +6129,6 @@ heap_prepare_freeze_tuple(HeapTupleHeader tuple, frz->t_infomask |= HEAP_XMIN_FROZEN; changed = true; - xmin_frozen = true; } } -- 2.17.1 --6c2NcOVqGQ03X4Wi--