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 1hqwYd-0006bk-VC for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2019 09:30:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqwYb-00053U-N1 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2019 09:30:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqwYb-00053M-9a for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2019 09:30:33 +0000 Received: from [212.85.157.172] (helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hqwYT-0006YX-Bq for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2019 09:30:32 +0000 Received: from firost (abordeaux-656-1-241-32.w90-38.abo.wanadoo.fr [90.38.33.32]) by mail.dalibo.com (Postfix) with ESMTPSA id 351AA20262; Fri, 26 Jul 2019 11:30:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1564133421; bh=IEB8wCnqYN/HjfA0A19ONRa4w+zJyib/7wj01Q7YDB0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QqjfeHp4QSuWfyMq/3npwaj3UTXii/c2/0cRyYQ3Iuq7LkvUOqPvH4Zik0O7dhQnr f9iINE88QUDjgZVQmdVCJtgcUABmMTV4BYY/lvH3ZvHCnrponTM8O33BV7CMfUKax7 Wu+jzZx5TFCUtXM0HduqBJd0TJ35KR5l3za2/8Do= Date: Fri, 26 Jul 2019 11:30:19 +0200 From: Jehan-Guillaume de Rorthais To: Kyotaro Horiguchi Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pg_walfile_name_offset can return inconsistent values Message-ID: <20190726113019.0a3b34c7@firost> In-Reply-To: <20190726.172120.101752680.horikyota.ntt@gmail.com> References: <20190726.172120.101752680.horikyota.ntt@gmail.com> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 212.85.157.172 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 26 Jul 2019 17:21:20 +0900 (Tokyo Standard Time) Kyotaro Horiguchi wrote: > Hello. > > While looking [1], I noticed that pg_walfile_name_offset behaves > somewhat oddly at segment boundary. > > select * from (values ('0/16ffffff'), ('0/17000000'), ('0/17000001')) as > t(lsn), lateral pg_walfile_name_offset(lsn::pg_lsn); > lsn | file_name | file_offset > ------------+--------------------------+------------- > 0/16ffffff | 000000020000000000000016 | 16777215 > 0/17000000 | 000000020000000000000016 | 0 > 0/17000001 | 000000020000000000000017 | 1 > > > The file names are right as defined, but the return value of the > second line wrong, or at least misleading. +1 I noticed it as well and put this report on hold while working on my patch. Thanks for reporting this! > It should be (16, 1000000) or (16, FFFFFF). The former is out-of-domain so we > would have no way than choosing the latter. I'm not sure the purpose of > the second output parameter, thus the former might be right > decision. > > The function returns the following result after this patch is > applied. > > select * from (values ('0/16ffffff'), ('0/17000000'), ('0/17000001')) as > t(lsn), lateral pg_walfile_name_offset(lsn::pg_lsn); > lsn | file_name | file_offset > ------------+--------------------------+------------- > 0/16ffffff | 000000020000000000000016 | 16777214 > 0/17000000 | 000000020000000000000016 | 16777215 > 0/17000001 | 000000020000000000000017 | 0 So you shift the file offset for all LSN by one byte? This could lead to regression in various tools relying on this function. Moreover, it looks weird as the LSN doesn't reflect the given offset anymore (FFFFFF <> 16777214, 000001 <> 0, etc). Another solution might be to return the same result when for both 0/16ffffff and 0/17000000, but it doesn't feel right either. So in fact, returning 0x1000000 seems to be the cleaner result to me. Regards,