Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWXyC-0006sq-Er for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2020 04:17:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jWXyB-0006ii-BH for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2020 04:17:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWXyB-0006iU-4p for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2020 04:17:11 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWXy7-0004TG-3g for pgsql-hackers@postgresql.org; Thu, 07 May 2020 04:17:09 +0000 Received: from hnk.local (p2358024-ipbf2221funabasi.chiba.ocn.ne.jp [114.177.56.24]) by oss.nttdata.com (Postfix) with ESMTPSA id 3432A60256; Thu, 7 May 2020 13:17:02 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at oss.nttdata.com Subject: Re: +(pg_lsn, int8) and -(pg_lsn, int8) operators To: Kyotaro Horiguchi Cc: robertmhaas@gmail.com, jgdr@dalibo.com, michael@paquier.xyz, pgsql-hackers@postgresql.org References: <20200427.104147.1848676018835134301.horikyota.ntt@gmail.com> <20200507.112109.323063386127165903.horikyota.ntt@gmail.com> From: Fujii Masao Message-ID: <4b4dd062-631e-dd58-a46a-bff532ace3f6@oss.nttdata.com> Date: Thu, 7 May 2020 13:17:01 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200507.112109.323063386127165903.horikyota.ntt@gmail.com> 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 2020/05/07 11:21, Kyotaro Horiguchi wrote: > At Tue, 28 Apr 2020 12:56:19 +0900, Fujii Masao wrote in >> Yes. Attached is the updated version of the patch, which introduces >> +(pg_lsn, numeric) and -(pg_lsn, numeric) operators. >> To implement them, I added also numeric_pg_lsn() function that >> converts numeric to pg_lsn. > > + into and substracted from LSN using the + and > > s/substracted/subtracted/ > (This still remains in the latest version) Thanks! Will fix this. > > +static bool > +numericvar_to_uint64(const NumericVar *var, uint64 *result) > > Other numricvar_to_xxx() functions return an integer value that means > success by 0 and failure by -1, which is one of standard signature of > this kind of functions. I don't see a reason for this function to > have different signatures from them. Unless I'm missing something, other functions also return boolean. For example, static bool numericvar_to_int32(const NumericVar *var, int32 *result); static bool numericvar_to_int64(const NumericVar *var, int64 *result); > > + /* XXX would it be better to return NULL? */ > + if (NUMERIC_IS_NAN(num)) > + ereport(ERROR, > + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > + errmsg("cannot convert NaN to pg_lsn"))); > > The ERROR seems perfect to me since NaN is out of the domain of > LSN. log(-1) results in a similar error. > > On the other hand, the code above makes the + operator behave as the > follows. > > =# SELECT '1/1'::pg_lsn + 'NaN'::numeric; > ERROR: cannot convert NaN to pg_lsn > > This looks somewhat different from what actually wrong is. You mean that pg_lsn_pli() and pg_lsn_mii() should emit an error like "the number of bytes to add/subtract cannnot be NaN" when NaN is specified? > > + char buf[256]; > + > + /* Convert to numeric */ > + snprintf(buf, sizeof(buf), UINT64_FORMAT, lsn); > > The values larger than 2^64 is useless. So 32 (or any value larger > than 21) is enough for the buffer length. Could you tell me what the actual problem is when buf[256] is used? > > By the way coudln't we use int128 instead for internal arithmetic? I > think that makes the code simpler. I'm not sure if int128 is available in every environments. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION