Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYYrk-0001UR-1J for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2017 13:53:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cYYrj-0003rp-Kn for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2017 13:52:59 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cYYqH-0008H5-VF for pgsql-hackers@postgresql.org; Tue, 31 Jan 2017 13:51:30 +0000 Received: from mail-qt0-x236.google.com ([2607:f8b0:400d:c0d::236]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cYYqE-0003CP-6W for pgsql-hackers@postgresql.org; Tue, 31 Jan 2017 13:51:29 +0000 Received: by mail-qt0-x236.google.com with SMTP id k15so234319371qtg.3 for ; Tue, 31 Jan 2017 05:51:25 -0800 (PST) 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=0q6mFOQwUGTAi4p2X4Rx3niCdD3ojEzSkidv2HwmzCk=; b=ZCR7NoFLeZWZfe3nItO5RKANyVd865pQHS1O1Brc9BC5L7+Tnq/0LtWifV8Vm2HbOd IDMQKX98O+uUbes0EZwfh9eKWTknEwzJkNiWI46TzTuKHEPitKVICKUnd1bDjhHKmTFQ zRGQPnY7Ar5oPyor6JbOToh0s4F/9dHVlPSTxGTbcAS3KZpar2guUUIOQimxvb3Jkf1a G8LaN20ROKa2qdCvV70ohyh+BgG2CnOzSdGBasbY+k/JQaoIF0WVyEVKCD9T1efTpXxl C4pux5vfO4YOyFdf/QGSl+PE4DSQi/rjiEX/dTgbtzwPK00Oe/lHDMw9k5dGTG9sIXwD wSNA== 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=0q6mFOQwUGTAi4p2X4Rx3niCdD3ojEzSkidv2HwmzCk=; b=XkngAc+CtW9IkHAMzvb0sWTzRu/QCk9cq2XgDO+ZzO+9A40y5cY4NM33w53smw4qj/ OAfNlCwhHDR2p1iRxx6TdBFIebClRHqYa/NZkQujtdF3EVNUB4IvnYDeV5NNHWKdjprM RoFIVtDlf41gHUzrQQFEmBKtVt3gE4yfe2cKqlps0MCqjaXrERjFvbcidLoUQcF53gc/ njYxYOrAJkU+lF89Ut/67nsqfxeJmLaF4fjBQWn03H+DgitA75hk3bGgakRg2+SwBR10 QpO51rFs/H/pUzb8pW0XlaLppjt/CPKMbG06eW8oMl/90VmM/qJunCK01NSNlP6bsYvN XmjA== X-Gm-Message-State: AIkVDXKCFnuugqzpinCZk7CcBXfUptF/8/+TZ68UjTNkLp+FYJ6Mo23juAhvSael8A+hF33f X-Received: by 10.237.59.28 with SMTP id p28mr24525855qte.152.1485870684140; Tue, 31 Jan 2017 05:51:24 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.217.211.239]) by smtp.gmail.com with ESMTPSA id f126sm6150248qkc.47.2017.01.31.05.51.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jan 2017 05:51:23 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 46710F20; Tue, 31 Jan 2017 10:51:21 -0300 (CLST) Date: Tue, 31 Jan 2017 10:51:21 -0300 From: Alvaro Herrera To: Pavan Deolasee Cc: Jaime Casanova , Haribabu Kommi , Tomas Vondra , pgsql-hackers Subject: Re: Patch: Write Amplification Reduction Method (WARM) Message-ID: <20170131135121.sy6yzt4yr6tqbfhs@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Pavan Deolasee wrote: > On Thu, Jan 26, 2017 at 2:38 AM, Alvaro Herrera > wrote: > > The simple_heap_update + CatalogUpdateIndexes pattern is getting > > obnoxious. How about creating something like catalog_heap_update which > > does both things at once, and stop bothering each callsite with the WARM > > stuff? > > What I realised that there are really 2 patterns: > 1. simple_heap_insert, CatalogUpdateIndexes > 2. simple_heap_update, CatalogUpdateIndexes > > There are only couple of places where we already have indexes open or have > more than one tuple to update, so we call CatalogIndexInsert directly. What > I ended up doing in the attached patch is add two new APIs which combines > the two steps of each of these patterns. It seems much cleaner to me and > also less buggy for future users. I hope I am not missing a reason not to > do combine these steps. CatalogUpdateIndexes was just added as a convenience function on top of a very common pattern. If we now have a reason to create a second one because there are now two very common patterns, it seems reasonable to have two functions. I think I would commit the refactoring to create these functions ahead of the larger WARM patch, since I think it'd be bulky and largely mechanical. (I'm going from this description; didn't read your actual code.) > > +#define HeapTupleHeaderGetNextTid(tup, next_ctid) \ > > +do { \ > > + AssertMacro(!((tup)->t_infomask2 & HEAP_LATEST_TUPLE)); \ > > + ItemPointerCopy(&(tup)->t_ctid, (next_ctid)); \ > > +} while (0) > > > Actually, I think this macro could just return the TID so that it can be > > used as struct assignment, just like ItemPointerCopy does internally -- > > callers can do > > ctid = HeapTupleHeaderGetNextTid(tup); > > While I agree with your proposal, I wonder why we have ItemPointerCopy() in > the first place because we freely copy TIDs as struct assignment. Is there > a reason for that? And if there is, does it impact this specific case? I dunno. This macro is present in our very first commit d31084e9d1118b. Maybe it's an artifact from the Lisp to C conversion. Even then, we had some cases of iptrs being copied by struct assignment, so it's not like it didn't work. Perhaps somebody envisioned that the internal details could change, but that hasn't happened in two decades so why should we worry about it now? If somebody needs it later, it can be changed then. > There is one issue that bothers me. The current implementation lacks > ability to convert WARM chains into HOT chains. The README.WARM has some > proposal to do that. But it requires additional free bit in tuple header > (which we don't have) and of course, it needs to be vetted and implemented. > If the heap ends up with many WARM tuples, then index-only-scans will > become ineffective because index-only-scan can not skip a heap page, if it > contains a WARM tuple. Alternate ideas/suggestions and review of the design > are welcome! t_infomask2 contains one last unused bit, and we could reuse vacuum full's bits (HEAP_MOVED_OUT, HEAP_MOVED_IN), but that will need some thinking ahead. Maybe now's the time to start versioning relations so that we can ensure clusters upgraded to pg10 do not contain any of those bits in any tuple headers. I don't have any ideas regarding the estate passed to recheck yet -- haven't looked at the callsites in detail. I'll give this another look later. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers