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 1lW6Zf-000342-UC for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Apr 2021 00:06:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lW6Ze-0006Ts-PD for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Apr 2021 00:06:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lW6Ze-0006Tk-CW for pgsql-hackers@lists.postgresql.org; Tue, 13 Apr 2021 00:06:34 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lW6ZX-0007LH-FK for pgsql-hackers@postgresql.org; Tue, 13 Apr 2021 00:06:33 +0000 Received: by mail-pg1-x52a.google.com with SMTP id w10so10652304pgh.5 for ; Mon, 12 Apr 2021 17:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=w8zbcbzuBaYJFqWDT3d7nEF5e2SNC7lTPragpVzXPxg=; b=GO30oInAE6uX50rp85cugHYn1VgVDdKYVdf6aAk5BV5oWgfaqpK5jMVMJeDds+kCuB eIDX9WEpUWlgukpyCJETkWu5hPslY3GTxqdGgailbQ1Cl5+7EXIUCi8px32WasqdXO7S S6FjpUOGk82RNN3ju9h6llDXYKSPHfxKtyehQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=w8zbcbzuBaYJFqWDT3d7nEF5e2SNC7lTPragpVzXPxg=; b=eVNlEy5vTzoDlaN6SipSD/FzZYeIc3sS0cW4+nwrpkyGICkbLjdKy8rbCZkOPgeLzt DG6LECbPr48S8OUYQxeTOtuT1wggoVqTwQiJS6DKLRjj4RbKf+6tbR5QLXBfyVKS+zsw czdxsNmN/fS4CBqIgzOkySYFs2GCwPMhgWWkivPBiSJYMZ3v8x0Jx0xKcWDXJEdfevDr 8caBbAp6Th2o93dFdPsECE0jqkFOiOwOUPY9d3Mx+NPzC/eh+7TkxSNaLbrqzSOyJoZ6 9Zm48kcADdtrs36BWnqe8/YuxAx9C6a47LyPbJX6fFy7uzhGwXHcxJmJiOWKw6XGJ8pv goeQ== X-Gm-Message-State: AOAM532RwHW3MdvCG8+p/Hfy5cakCZq7ufxs+eOJHHydgNt1wwws0zvg zm/u1rWgJoVv0AcXvVEA66ko1w== X-Google-Smtp-Source: ABdhPJzSNE3ugKlcin+Y5+mSxOCi1y9X6X0mjXyayYGt/kMWT5kiJCNbnMryRZam1LxRnLSZlwRqOQ== X-Received: by 2002:a65:6483:: with SMTP id e3mr29839636pgv.208.1618272386111; Mon, 12 Apr 2021 17:06:26 -0700 (PDT) Received: from ?IPv6:2601:646:101:7fda:c162:4dcc:3f5d:f63c? ([2601:646:101:7fda:c162:4dcc:3f5d:f63c]) by smtp.gmail.com with ESMTPSA id 123sm119894pfz.127.2021.04.12.17.06.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Apr 2021 17:06:25 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_98F2423C-AC4D-4CE2-A2A4-E146742E04CA" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: Have I found an interval arithmetic bug? From: Bryn Llewellyn In-Reply-To: <3135041.1618270701@sss.pgh.pa.us> Date: Mon, 12 Apr 2021 17:06:24 -0700 Cc: Zhihong Yu , Justin Pryzby , Isaac Morland , John W Higgins , PostgreSQL-development Message-Id: <32AF8412-44F2-4861-AFF6-BB8FD5132531@yugabyte.com> References: <20210403022126.GG29126@momjian.us> <20210405163310.GP6592@telsasoft.com> <20210405180158.GB12179@momjian.us> <20210408172444.GC6909@momjian.us> <20210412161842.GA22319@momjian.us> <8707105F-C45D-4ACB-8F71-51CE5BED58A5@yugabyte.com> <20210412232237.GA4231@momjian.us> <3135041.1618270701@sss.pgh.pa.us> To: Tom Lane PostgreSQL , Bruce Momjian X-Mailer: Apple Mail (2.3654.60.0.2.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_98F2423C-AC4D-4CE2-A2A4-E146742E04CA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > tgl@sss.pgh.pa.us wrote: >=20 > bruce@momjian.us writes: >> bryn@yugabyte.com wrote: >>> After all, you've bitten the bullet now and changed the behavior. = This means that the semantics of some extant applications will change. = So... in for a penny, in for a pound? >=20 >> The docs now say: >=20 >> Field values can have fractional parts; for example, = '1.5 >> weeks' or '01:02:03.45'. The = fractional >> --> parts are used to compute appropriate values for the next = lower-order >> internal fields (months, days, seconds). >=20 >> meaning fractional years flows to the next lower internal unit, = months, and no further. Fractional months would flow to days. The idea = of not flowing past the next lower-order internal field is that the = approximations between units are not precise enough to flow accurately. >=20 > Um, what's the argument for down-converting AT ALL? The problem is = precisely that any such conversion is mostly fictional. >=20 >> With my patch, the output is now: >=20 >> SELECT INTERVAL '3 years 10.241604 months'; >> interval >> ------------------------ >> 3 years 10 mons 7 days >=20 >> It used to flow to seconds. >=20 > Yeah, that's better than before, but I don't see any principled = argument for it not to be "3 years 10 months", full stop. Tom, I fully support your suggestion to have no flow down at all. Please = may this happen! However, the new rule must be described in terms of the = three fields of the internal representation: [months, days, seconds]. = This representation is already documented. Don=E2=80=99t forget that '731.42587 hours=E2=80=99 is read back as = "731:25:33.132" (or, if you prefer, 731 hours, 25 minutes, and 33.132 = seconds if you use "extract" and your own pretty print). But we don=E2=80=99= t think of this as =E2=80=9Cflow down=E2=80=9D. Rather, it=E2=80=99s = just a conventional representation of the seconds field of the internal = representation. I could go on. But you all know what I mean. By the way, I made a nice little demo (for my doc project). It shows = that: (1) if you pick the right date-time just before a DST change, and do the = addition in the right time zone, then adding 24 hours gets a different = answer than adding one day. (2) if you pick the right date-time just before 29-Feb in a leap year, = then adding 30 days gets a different answer than adding one month. You all know why. And though the doc could explain and illustrate this = better, it does tell you to expect this. It also says that the = difference in semantics that these examples show is the reason for the = three-field internal representation. It seems to me that both the age-old behavior that vanilla 13.2 = exhibits, and the behavior in the regime of Bruce=E2=80=99s patch are = like adding 2.2 oranges to 1.3 oranges and getting 3 oranges and 21 = apples (because 1 orange is conventionally the same as 42 apples). Bruce = made a step in the right direction by stopping oranges convert all the = way down to bananas. But it would be so much better to get rid of this = false equivalence business altogether. --Apple-Mail=_98F2423C-AC4D-4CE2-A2A4-E146742E04CA Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
tgl@sss.pgh.pa.us = wrote:

bruce@momjian.us writes:
bryn@yugabyte.com wrote:
After all, you've bitten the bullet now and = changed the behavior. This means that the semantics of some extant = applications will change. So... in for a penny, in for a pound?

The docs now say:

=     Field values can have fractional parts; =  for example, <literal>'1.5
=     weeks'</literal> or = <literal>'01:02:03.45'</literal>.  The fractional
-->  parts are used to compute appropriate values for = the next lower-order
    internal = fields (months, days, seconds).

meaning fractional years = flows to the next lower internal unit, months, and no further. =  Fractional months would flow to days.  The idea of = not flowing past the next lower-order internal field is that = the approximations between units are not precise enough to flow = accurately.

Um, what's the = argument for down-converting AT ALL?  The problem is precisely = that any such conversion is mostly fictional.

With my patch, the = output is now:

SELECT INTERVAL '3 years = 10.241604 months';
=        interval
= ------------------------
3 years = 10 mons 7 days

It used to flow to seconds.

Yeah, that's better than before, = but I don't see any principled argument for it not to be "3 years = 10 months", full stop.

Tom, = I fully support your suggestion to have no flow down at all. Please may = this happen! However, the new rule must be described in terms of the = three fields of the internal representation: [months, days, seconds]. = This representation is = already documented.

Don=E2=80=99t forget that '731.42587 hours=E2=80=99 is read = back as "731:25:33.132" (or, if you prefer, 731 hours, 25 minutes, = and 33.132 seconds if you use "extract" and your own pretty print). But = we don=E2=80=99t think of this as =E2=80=9Cflow down=E2=80=9D. Rather, = it=E2=80=99s just a conventional representation of the seconds field of = the internal representation. I could go on. But you all know what I = mean.

By the = way, I made a nice little demo (for my doc project). It shows = that:

(1) if = you pick the right date-time just before a DST change, and do the = addition in the right time zone, then adding 24 hours gets a different = answer than adding one day.

(2) if you pick the right date-time just before 29-Feb in a = leap year, then adding 30 days gets a different answer than adding one = month.

You all = know why. And though the doc could explain and illustrate this better, = it does tell you to expect this. It also says that the difference in = semantics that these examples show is the reason for the three-field = internal representation.

It seems to me that both the age-old behavior that vanilla = 13.2 exhibits, and the behavior in the regime of Bruce=E2=80=99s patch = are like adding 2.2 oranges to 1.3 oranges and getting 3 oranges and 21 = apples (because 1 orange is conventionally the same as 42 apples). = Bruce made a step in the right direction by stopping oranges convert all = the way down to bananas. But it would be so much better to get rid of = this false equivalence business altogether.


= --Apple-Mail=_98F2423C-AC4D-4CE2-A2A4-E146742E04CA--