Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ctbYP-0004D9-1S for pgsql-general@arkaria.postgresql.org; Thu, 30 Mar 2017 15:00:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ctbYO-0002Kk-KF for pgsql-general@arkaria.postgresql.org; Thu, 30 Mar 2017 15:00:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ctbVv-0001iX-IE for pgsql-general@postgresql.org; Thu, 30 Mar 2017 14:57:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ctbVt-0006Yb-2D for pgsql-general@postgresql.org; Thu, 30 Mar 2017 14:57:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v2UEvJLu002088; Thu, 30 Mar 2017 10:57:19 -0400 From: Tom Lane To: Kyotaro HORIGUCHI cc: adrian.klaver@aklaver.com, frazer@frazermclean.co.uk, pgsql-general@postgresql.org Subject: Re: Unexpected interval comparison In-reply-to: <20170330.164651.249668658.horiguchi.kyotaro@lab.ntt.co.jp> References: <1490104629.422698.918452336.26FA96B7@webmail.messagingengine.com> <30765.1490107336@sss.pgh.pa.us> <375c9e5a-960f-942c-913f-55632a1f0a90@aklaver.com> <20170330.164651.249668658.horiguchi.kyotaro@lab.ntt.co.jp> Comments: In-reply-to Kyotaro HORIGUCHI message dated "Thu, 30 Mar 2017 16:46:51 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2086.1490885839.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 30 Mar 2017 10:57:19 -0400 Message-ID: <2087.1490885839@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Kyotaro HORIGUCHI writes: > At Tue, 21 Mar 2017 07:52:25 -0700, Adrian Klaver wrote in <375c9e5a-960f-942c-913f-55632a1f0a90@aklaver.com> >> On 03/21/2017 07:42 AM, Tom Lane wrote: >>> It looks like the problem is overflow of the result of interval_cmp_val= ue, >>> because it's trying to compute >>> =3D# select '32618665'::int8 * 30 * 86400 * 1000000; >>> ERROR: bigint out of range >>> It's not immediately obvious how to avoid that while preserving the >>> same comparison semantics :-( > Detecting the overflow during the conversion can fix it and > preserving the semantics (except value range). The current code > tells a lie anyway for the cases but I'm not sure limting the > range of value is acceptable or not. I don't think it is. It'd cause failures in attempting to enter very large interval values into btree indexes, for instance. A possible solution is to manually work in wider-than-64-bit arithmetic, that is compute the comparison values div and mod some pretty-large number and then compare the two halves. I seem to recall that we did something similar in a few cases years ago, before we were willing to assume that every machine had 64-bit integer support. Of course, for machines having int128, you could just use that type directly. I'm not sure how widespread that support is nowadays. Maybe a 95%-good-enough solution is to use int128 if available and otherwise throw errors for intervals exceeding 64 bits. regards, tom lane --=20 Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general