Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEePN-00031N-1e for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 17:54:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEePL-000231-0o for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 17:54:27 +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.89) (envelope-from ) id 1gEePK-00022p-L1 for pgsql-hackers@lists.postgresql.org; Mon, 22 Oct 2018 17:54:26 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEePH-0007zZ-VE for pgsql-hackers@postgresql.org; Mon, 22 Oct 2018 17:54:26 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 490E321C2116; Mon, 22 Oct 2018 20:54:22 +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.0.103] (unknown [5.79.142.119]) (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 06D8621C1F6B; Mon, 22 Oct 2018 20:54:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1540230862; bh=tytlR/xWEnNfl9N7D0KfenNpYs/B7ll+fGpGOdT92YY=; h=Subject:To:References:From:Date:In-Reply-To; b=O/tCnlaluociaMxq2telvJ2LkcNkVcKYjg5QJ0o3VSlX7g5SHFNkHZ9K+qp8Y2wQ3 Q7AL0t3BID4Pp/qodQIxWNhcnvijtS6W1pcsTtM9euXFPcjRGKgiEbV0+3j8IU5egW Tcuu6IJGBSvFrSWOAI7QX+/Uu1nPqGsWRpwjasRA= Subject: Re: [PATCH] XLogReadRecord returns pointer to currently read page To: Heikki Linnakangas , PostgreSQL-Dev References: <25cc0d31-a5c7-2b7d-e66e-f5cc9f2d4985@iki.fi> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <5f701ad0-6c3c-67f2-e5ce-dbf2f60a7d2d@postgrespro.ru> Date: Mon, 22 Oct 2018 22:54:19 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <25cc0d31-a5c7-2b7d-e66e-f5cc9f2d4985@iki.fi> 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 22.10.2018 2:06, Heikki Linnakangas wrote: > On 17/08/2018 06:47, Andrey Lepikhov wrote: >> I propose the patch for fix one small code defect. >> The XLogReadRecord() function reads the pages of a WAL segment that >> contain a WAL-record. Then it creates a readRecordBuf buffer in private >> memory of a backend and copy record from the pages to the readRecordBuf >> buffer. Pointer 'record' is set to the beginning of the readRecordBuf >> buffer. >> >> But if the WAL-record is fully placed on one page, the XLogReadRecord() >> function forgets to bind the "record" pointer with the beginning of the >> readRecordBuf buffer. In this case, XLogReadRecord() returns a pointer >> to an internal xlog page. This patch fixes the defect. > > Hmm. I agree it looks weird the way it is. But I wonder, why do we even > copy the record to readRecordBuf, if it fits on the WAL page? Returning > a pointer to the xlog page buffer seems OK in that case. What if we > remove the memcpy(), instead? It depends on the PostgreSQL roadmap. If we want to compress main data and encode something to reduce a WAL-record size, than the representation of the WAL-record in shared buffers (packed) and in local memory (unpacked) will be different and the patch is needed. If something like this should not be in the PostgreSQL core, then it is more efficient to remove memcpy(), of course. I vote for the patch. -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company