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 1gtsY0-0004lC-6n for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Feb 2019 11:17:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtsXy-0007B5-SO for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Feb 2019 11:17:46 +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 1gtsXy-00079l-Eb for pgsql-hackers@lists.postgresql.org; Wed, 13 Feb 2019 11:17:46 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtsXu-00082x-Tr for pgsql-hackers@lists.postgresql.org; Wed, 13 Feb 2019 11:17:46 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id D260221CDB78; Wed, 13 Feb 2019 14:17:41 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id A0D5821CDB6D; Wed, 13 Feb 2019 14:17:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1550056661; bh=tyKx2aKlCoAGf/ls/zZL2BhbXjSPFnvUnwh0BlRVBpQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=GmjF1VPnyumkV/fYnQgubN7WyhokX1jPczjn1+EBF0diMJhYy3LCL96smQfi0SFjm 5uG7mlS8ujAt59ykStWeaFTcnublGrG0wOThBRsLRV2hPbkwivumEwQjtYHk5oRP+I 7SYqOmSjv8d34wRihAMvmuwDOF94NgynoZPt3bCk= Subject: Re: [PATCH] xlogreader: do not read a file block twice To: Andrey Lepikhov , pgsql-hackers@lists.postgresql.org Cc: Grigory Smolkin References: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> <93d74870-3217-7ab3-b220-31cab64b7c7a@postgrespro.ru> From: Arthur Zakirov Message-ID: <9eaeb1cf-615e-2777-1e69-bc255f2528bd@postgrespro.ru> Date: Wed, 13 Feb 2019 14:17:41 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <93d74870-3217-7ab3-b220-31cab64b7c7a@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12.02.2019 20:47, Andrey Lepikhov wrote: > I looked at the history of the code changes: > > --------------------------------------------------------------- > 7fcbf6a405f (Alvaro Herrera 2013-01-16 16:12:53 -0300 539) reqLen < > state->readLen) > > 1bb2558046c (Heikki Linnakangas 2010-01-27 15:27:51 +0000 9349) > targetPageOff == readOff && targetRecOff < readLen) > > eaef111396e (Tom Lane 2006-04-03 23:35:05 +0000 3842) > len = XLOG_BLCKSZ - RecPtr->xrecoff % XLOG_BLCKSZ; > 4d14fe0048c (Tom Lane 2001-03-13 01:17:06 +0000 3843) > if (total_len > len) > --------------------------------------------------------------- > > In the original code of Tom Lane, condition (total_len > len) caused a > page reread from disk. As I understand it, this is equivalent to your > proposal. > Th code line in commit 1bb2558046c seems tantamount to the corresponding > line in commit 7fcbf6a405f but have another semantics: the targetPageOff > value can't be more or equal XLOG_BLCKSZ, but the reqLen value can be. > It may be a reason of appearance of possible mistake, introduced by > commit 7fcbf6a405f. Thank you for your research. Indeed, it makes sense now. In my case after reading a page both `reqLen` and `state->readLen` equal to XLOG_BLCKSZ. This leads to a page reread, since `pageptr` is the same as the previous read. But `targetRecOff` is different in the second case because we want to read next record, which probably doesn't fit into the page wholly (that's why `reqLen` is equal to XLOG_BLCKSZ). -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company