Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWQZB-0006O1-S0 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2017 16:37:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cWQZB-0002Ne-7H for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2017 16:37:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cWQZ9-0002Hn-Jk for pgsql-hackers@postgresql.org; Wed, 25 Jan 2017 16:36:59 +0000 Received: from mail-qt0-x236.google.com ([2607:f8b0:400d:c0d::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cWQZ2-0003wZ-Sq for pgsql-hackers@postgresql.org; Wed, 25 Jan 2017 16:36:58 +0000 Received: by mail-qt0-x236.google.com with SMTP id x49so25467725qtc.2 for ; Wed, 25 Jan 2017 08:36:52 -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=o65FnKjyeee85G5vYEPzPj8nwWvFWZoilagd+fWkiPc=; b=aDpR59lssCwNE5cuMreUCswkbmXD89SkHY2Y2zLgjA+L1BrI8ulV/Ka/CPPWnqUG0l HOPEAw9UpEXaBSG8Te1BwkTNggIQtYo4xvzjku8wqRnIeV625MoMMDJUGW5lZ4ixb482 vaa5ZhSqw4ObB3FL9kNHeKjepj2ifSqDqeGLS3vDygUnmEm3L3n2L25/EZiYCldTRtfU u9ajn2Xwvu06ENDXn5oLlCBHsTv9wDzvwOcJRy8zB+iv4Qrq24idYFylpf29JQ+3AIQM wmdr1kJ5wsW28FiBbwAoBcwaOvjFaFnt4b+3jHTQp0z1F+ZUTEBQKgV/SWclnHIG6+Vw 1+uA== 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=o65FnKjyeee85G5vYEPzPj8nwWvFWZoilagd+fWkiPc=; b=V7RohmvgGVmcGee5iGCG0vjMDJpmHlEJ/2vDL/d/L8DsTt56/ZD6IJGi5JLUz3l92Y 7EssBJKaFSM4PqFoN0vBYh44pZOXi4tkRzYk98uN0SAyOZm3+U6qih2yt0D9PrtRK+4H vSSJytQyCymomDgsloSRuSm9p5Ew/edCDoHbhAwc3cK/WGOoHwDjFju73ZW9WZcGOAIa mE+xeWIA4g+kD02pdRjl67X2wWog7M2xqa8M9j/WyENMDMivPZ0t69HKhXmxrYyzfLkp C4F/VBy7XqPbeSNdgvB2+TNgpi0CQU/hZg+e/qbJIi1BLMDSEe57nw6fpGQMVJRQRDMS /CBA== X-Gm-Message-State: AIkVDXKJPRiodtbCDvgMRweXNI8dHPibXDC7zlWxC59JLQmBEkVVsi83JkuDeJpF3i5Mj/MQ X-Received: by 10.55.18.76 with SMTP id c73mr33988742qkh.119.1485362210992; Wed, 25 Jan 2017 08:36:50 -0800 (PST) Received: from alvin.alvh.no-ip.org ([179.57.112.237]) by smtp.gmail.com with ESMTPSA id g32sm19301428qtd.28.2017.01.25.08.36.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jan 2017 08:36:50 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 41B91EF9; Wed, 25 Jan 2017 13:36:48 -0300 (CLST) Date: Wed, 25 Jan 2017 13:36:48 -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: <20170125163648.w3q24ifflvcemjpj@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 Reading 0001_track_root_lp_v9.patch again: > +/* > + * We use the same HEAP_LATEST_TUPLE flag to check if the tuple's t_ctid field > + * contains the root line pointer. We can't use the same > + * HeapTupleHeaderIsHeapLatest macro because that also checks for TID-equality > + * to decide whether a tuple is at the of the chain > + */ > +#define HeapTupleHeaderHasRootOffset(tup) \ > +( \ > + ((tup)->t_infomask2 & HEAP_LATEST_TUPLE) != 0 \ > +) > > +#define HeapTupleHeaderGetRootOffset(tup) \ > +( \ > + AssertMacro(((tup)->t_infomask2 & HEAP_LATEST_TUPLE) != 0), \ > + ItemPointerGetOffsetNumber(&(tup)->t_ctid) \ > +) Interesting stuff; it took me a bit to see why these macros are this way. I propose the following wording which I think is clearer: Return whether the tuple has a cached root offset. We don't use HeapTupleHeaderIsHeapLatest because that one also considers the slow case of scanning the whole block. Please flag the macros that have multiple evaluation hazards -- there are a few of them. > +/* > + * If HEAP_LATEST_TUPLE is set in the last tuple in the update chain. But for > + * clusters which are upgraded from pre-10.0 release, we still check if c_tid > + * is pointing to itself and declare such tuple as the latest tuple in the > + * chain > + */ > +#define HeapTupleHeaderIsHeapLatest(tup, tid) \ > +( \ > + (((tup)->t_infomask2 & HEAP_LATEST_TUPLE) != 0) || \ > + ((ItemPointerGetBlockNumber(&(tup)->t_ctid) == ItemPointerGetBlockNumber(tid)) && \ > + (ItemPointerGetOffsetNumber(&(tup)->t_ctid) == ItemPointerGetOffsetNumber(tid))) \ > +) I suggest rewording this comment as: Starting from PostgreSQL 10, the latest tuple in an update chain has HEAP_LATEST_TUPLE set; but tuples upgraded from earlier versions do not. For those, we determine whether a tuple is latest by testing that its t_ctid points to itself. (as discussed, there is no "10.0 release"; it's called the "10 release" only, no ".0". Feel free to use "v10" or "pg10"). > +/* > + * Get TID of next tuple in the update chain. Caller should have checked that > + * we are not already at the end of the chain because in that case t_ctid may > + * actually store the root line pointer of the HOT chain whose member this > + * tuple is. > + */ > +#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); or more precisely, this pattern > + if (!HeapTupleHeaderIsHeapLatest(tp.t_data, &tp.t_self)) > + HeapTupleHeaderGetNextTid(tp.t_data, &hufd->ctid); > + else > + ItemPointerCopy(&tp.t_self, &hufd->ctid); becomes hufd->ctid = HeapTupleHeaderIsHeapLatest(foo) ? HeapTupleHeaderGetNextTid(foo) : &tp->t_self; or something like that. I further wonder if it'd make sense to hide this into yet another macro. The API of RelationPutHeapTuple appears a bit contorted, where root_offnum is both input and output. I think it's cleaner to have the argument be the input, and have the output offset be the return value -- please check whether that simplifies things; for example I think this: > + root_offnum = InvalidOffsetNumber; > + RelationPutHeapTuple(relation, buffer, heaptup, false, > + &root_offnum); becomes root_offnum = RelationPutHeapTuple(relation, buffer, heaptup, false, InvalidOffsetNumber); Please remove the words "must have" in this comment: > + /* > + * Also mark both copies as latest and set the root offset information. If > + * we're doing a HOT/WARM update, then we just copy the information from > + * old tuple, if available or computed above. For regular updates, > + * RelationPutHeapTuple must have returned us the actual offset number > + * where the new version was inserted and we store the same value since the > + * update resulted in a new HOT-chain > + */ Many comments lack finishing periods in complete sentences, which looks odd. Please fix. I have not looked at the other patch yet. -- Á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