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 1hqvTn-0003Uy-Pv for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2019 08:21:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqvTm-0001O0-Lo for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2019 08:21:30 +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 1hqvTm-0001Ns-Am for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2019 08:21:30 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqvTj-0003Oo-FO for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2019 08:21:29 +0000 Received: by mail-pl1-x643.google.com with SMTP id b3so24491786plr.4 for ; Fri, 26 Jul 2019 01:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:subject:from:user-agent:mime-version :content-transfer-encoding; bh=JAVL2x9fMmEJGTUQjQ6Ooro4TbqXWkJjGRN9y66W7WQ=; b=pDm48s3veTuMPNmKw7WNLbQg4NOmqpcwpereCc5GINHQiMLfyBv6sPudE5wBjubypy n/cyX5ZW56CJyObK4YbS3LkrZsIxzCdJ4ujvvLxIhYJZsLUWWz63eYAIk8v7xnEBJwi7 O87idwOwydmIMAePgsLu+NumSDth+Y5o+AG0zV7GdcCyTGi8v5E/rTu49ZC4Qyj3mwq/ PkIDVcOtSSjhV8asxrPG0h7V2e6akOVzEgzrs7Q7p0b5xBVxosehVvPhv9so9S5BXePS QpL+RWxItweWvxMgrvzufLQfpr8SsGHftQRWZcgiYXOi1HxpHo29L6hlRQN+0Pgo5D3P xxOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:subject:from:user-agent :mime-version:content-transfer-encoding; bh=JAVL2x9fMmEJGTUQjQ6Ooro4TbqXWkJjGRN9y66W7WQ=; b=QpyR0ubEEI0VD9utqJwYUSFD91XiE3KyQIAo5uyqUWMlaxRqJEMnDWaPnlhpkcf9nI C1ruk6KUFV7PrYYbGl7eY+QNYQbVU4jJ2ATShy1ujMHzApyXNgGoalMwimZ/91F+qFec HYuYlgj6S1TAZ133aM+FbExwvdc5UIEWTQi0j0Z+s99u3CjgXtYy9waHfZMbK0N5cqvn L6O7mcE4xzqPOqRvy7RS6Uon4Ai9sc1fDqYxrsEzpoqRZHxBj5I6VWVFrR+auB/wr8p9 CT8hBmPwkwmkLSLDXhtMPX6UTfdkyM+XkXJELm9Z7fNMN7EYVAuFMqNTe0TvXkWwzkRU bpeA== X-Gm-Message-State: APjAAAUc5xtldHwEAS2G8i9RuCrgwP6KesgEK97dL6+E3lSF86+ZsdJw dU3+TBkzrZaBqI07y/lgFJArPlrH X-Google-Smtp-Source: APXvYqxw8q91yKme5owbonAQR7sNslvdVXJGo8nV9Fo+roy8zX/02241/6Lsmz6JH5KgRZxhbvG7/g== X-Received: by 2002:a17:902:5c3:: with SMTP id f61mr88368273plf.98.1564129284009; Fri, 26 Jul 2019 01:21:24 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id r13sm73579027pfr.25.2019.07.26.01.21.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 26 Jul 2019 01:21:23 -0700 (PDT) Date: Fri, 26 Jul 2019 17:21:20 +0900 (Tokyo Standard Time) Message-Id: <20190726.172120.101752680.horikyota.ntt@gmail.com> To: pgsql-hackers@lists.postgresql.org Subject: pg_walfile_name_offset can return inconsistent values From: Kyotaro Horiguchi User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Jul_26_17_21_20_2019_557)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ----Next_Part(Fri_Jul_26_17_21_20_2019_557)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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. 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 regards. [1]: https://www.postgresql.org/message-id/20190725193808.1648ddc8@firost -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Fri_Jul_26_17_21_20_2019_557)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Fix-offset-of-pg_walfile_name_offset.patch"