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 1mFetn-0001fM-Uu for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 15:51:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFetm-0006Lh-N1 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 15:51:38 +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 1mFetm-0006L8-A8 for pgsql-hackers@lists.postgresql.org; Mon, 16 Aug 2021 15:51:38 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mFetj-0002xr-OU for pgsql-hackers@lists.postgresql.org; Mon, 16 Aug 2021 15:51:37 +0000 Received: by mail-lf1-x130.google.com with SMTP id p38so35547185lfa.0 for ; Mon, 16 Aug 2021 08:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W5OL2wX2ABWcoHybnltbDAh+a0WFXXg7x5idLN3ZeVo=; b=fMP600ikT6qYR/iZCh0BKwojNkS30frI5jUoaZhaSk8ou67+7c4W1faYTjkzAsG53z pyz+iE0uth0tA1cCY+msQ6cMaIc66DNwtZEJxhoNgt9sIMiozUuZHZuH+byojjlM1yIs I34cOIbYRwsGxBDo2b8wEJFfc/OI7U6gGnFF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W5OL2wX2ABWcoHybnltbDAh+a0WFXXg7x5idLN3ZeVo=; b=jxd020UC3aJ5YZjDBIoFcQiJH9Pi+lmMKdiGf1BzWLpRK+B8lSDd+o/3IiBIXDBNdA TFVe1QSDhW2BotpVPDaY/sKgFiIAJEorcMmglkrDSj4vtLentZx634wSbrGML7dMlTPu Kh+EyPKHYkZLLVk5kZjCeFSoAqM8i2Jw1p37bG8NuKlcLCRfSTZvUGa64KU/gm4B/44N 1RN18A4FoBPei14WXS5Chruv/nLzcYoJBNkbykmdFd53KHiNJrg/oGtJ07s5dph+eSmc V7Zc2JAFf8t8XuHsLOESiw+vUz1iq9BGhbt8k63r8hIxAodnD5XYewtis/vlPFJTWPcq w9Zw== X-Gm-Message-State: AOAM530bL+QOVCbxYTq1aKPdJ07cGzdaI67kLkC4FrJu28/AdzSBtyKL TiRN3Q8XrsxqNlbeLk7z2sITx/XCbujmUKFmDIwb/Q== X-Google-Smtp-Source: ABdhPJyt3FtXBWaCygrnuozXSc9uyo9KJ/Lt66R+JBPEOTFzLxowmovdGLshF1JMGTTH6tYCcBGP6nh/ucJfHd0fLLw= X-Received: by 2002:a05:6512:3e2a:: with SMTP id i42mr5046654lfv.535.1629129093924; Mon, 16 Aug 2021 08:51:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Zhihong Yu Date: Mon, 16 Aug 2021 08:57:12 -0700 Message-ID: Subject: Re: Window Function "Run Conditions" To: David Rowley Cc: PostgreSQL Developers Content-Type: multipart/alternative; boundary="000000000000efe26c05c9af2ce9" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efe26c05c9af2ce9 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 16, 2021 at 3:28 AM David Rowley wrote: > On Thu, 1 Jul 2021 at 21:11, David Rowley wrote: > > 1) Unsure of the API to the prosupport function. I wonder if the > > prosupport function should just be able to say if the function is > > either monotonically increasing or decreasing or neither then have > > core code build a qual. That would make the job of building new > > functions easier, but massively reduce the flexibility of the feature. > > I'm just not sure it needs to do more in the future. > > I looked at this patch again today and ended up changing the API that > I'd done for the prosupport functions. These just now set a new > "monotonic" field in the (also newly renamed) > SupportRequestWFuncMonotonic struct. This can be set to one of the > values from the newly added MonotonicFunction enum, namely: > MONOTONICFUNC_NONE, MONOTONICFUNC_INCREASING, MONOTONICFUNC_DECREASING > or MONOTONICFUNC_BOTH. > > I also added handling for a few more cases that are perhaps rare but > could be done with just a few lines of code. For example; COUNT(*) > OVER() is MONOTONICFUNC_BOTH as it can neither increase nor decrease > for a given window partition. I think technically all of the standard > set of aggregate functions could have a prosupport function to handle > that case. Min() and Max() could go a little further, but I'm not sure > if adding handling for that would be worth it, and if someone does > think that it is worth it, then I'd rather do that as a separate > patch. > > I put the MonotonicFunction enum in plannodes.h. There's nothing > specific about window functions or support functions. It could, for > example, be reused again for something else such as monotonic > set-returning functions. > > One thing which I'm still not sure about is where > find_window_run_conditions() should be located. Currently, it's in > allpaths.c but that does not really feel like the right place to me. > We do have planagg.c in src/backend/optimizer/plan, maybe we need > planwindow.c? > > David > Hi, + if ((res->monotonic & MONOTONICFUNC_INCREASING) == MONOTONICFUNC_INCREASING) The above can be simplified as 'if (res->monotonic & MONOTONICFUNC_INCREASING) ' Cheers --000000000000efe26c05c9af2ce9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Aug 16, 2021 at 3:28 AM David= Rowley <dgrowleyml@gmail.com> wrote:
On = Thu, 1 Jul 2021 at 21:11, David Rowley <dgrowleyml@gmail.com> wrote:
> 1) Unsure of the API to the prosupport function.=C2=A0 I wonder if the=
> prosupport function should just be able to say if the function is
> either monotonically increasing or decreasing or neither then have
> core code build a qual.=C2=A0 That would make the job of building new<= br> > functions easier, but massively reduce the flexibility of the feature.=
> I'm just not sure it needs to do more in the future.

I looked at this patch again today and ended up changing the API that
I'd done for the prosupport functions.=C2=A0 These just now set a new "monotonic" field in the (also newly renamed)
SupportRequestWFuncMonotonic struct. This can be set to one of the
values from the newly added MonotonicFunction enum, namely:
MONOTONICFUNC_NONE, MONOTONICFUNC_INCREASING, MONOTONICFUNC_DECREASING
or MONOTONICFUNC_BOTH.

I also added handling for a few more cases that are perhaps rare but
could be done with just a few lines of code. For example; COUNT(*)
OVER() is MONOTONICFUNC_BOTH as it can neither increase nor decrease
for a given window partition. I think technically all of the standard
set of aggregate functions could have a prosupport function to handle
that case. Min() and Max() could go a little further, but I'm not sure<= br> if adding handling for that would be worth it, and if someone does
think that it is worth it, then I'd rather do that as a separate
patch.

I put the MonotonicFunction enum in plannodes.h. There's nothing
specific about window functions or support functions. It could, for
example, be reused again for something else such as monotonic
set-returning functions.

One thing which I'm still not sure about is where
find_window_run_conditions() should be located. Currently, it's in
allpaths.c but that does not really feel like the right place to me.
We do have planagg.c in src/backend/optimizer/plan, maybe we need
planwindow.c?

David
Hi,

+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if ((res->monotonic & MONOTONICFUNC_= INCREASING) =3D=3D MONOTONICFUNC_INCREASING)

The a= bove can be simplified as 'if (res->monotonic & MONOTONICFUNC_IN= CREASING) '

Cheers
--000000000000efe26c05c9af2ce9--