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 1mGKZ3-0008OW-GQ for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Aug 2021 12:21:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mGKZ2-0001At-Eu for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Aug 2021 12:21:00 +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 1mGKZ2-0001Al-7Q for pgsql-hackers@lists.postgresql.org; Wed, 18 Aug 2021 12:21:00 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mGKYy-0007CX-U7 for pgsql-hackers@lists.postgresql.org; Wed, 18 Aug 2021 12:20:59 +0000 Received: by mail-yb1-xb30.google.com with SMTP id l144so4811179ybl.12 for ; Wed, 18 Aug 2021 05:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=rcEacjlNqCTVeqUc6kay0y1pIzWdd9iiHUdiQO/D9mA=; b=CCwOyiyI1MAndahoQW5rK0q2+mLRc0XYo3PcY/qWfmQqu1OO18INs22+VBdcFuFK4W dyEBRYlWAkv/u5ouzq2NX2E3/dRIHr6XxFVL9fVIuc2+Ptq1c8TFfwV9cXzpVcSqmNI+ W3IWJibASqiwO6/CUjPz5BM6s/Rh7cE0QxKO0L3/6xAkViPDJjfhEcHNqFeYx7LvEbSO qh6WBjPThRuZdGXkeGcm6dJHvr/R2hyBzK4PGtn2GAbStmZzo7e92K45FX39onbabES1 +zhTk3x/Wjo2F5p+7LAZHXEKD/Te2nx9zytiRzPHCQST8VqOYVb+jdcWBrSLvzNS6ix1 HYow== 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:content-transfer-encoding; bh=rcEacjlNqCTVeqUc6kay0y1pIzWdd9iiHUdiQO/D9mA=; b=iIb/hg7F8qjdfNIGycWwIa8CEn+drN+moUjx+zlswPpFE85UCZ8Ifs2Rqt5ej73+mJ JMhhilERGL7rH7QmY6z2uNDM9QOE7SII2ATDVzV/4lOlIc2A70t02peBx9k+voBjP2CW UrTq08Y71Tj/6U1GMg8U60x2Mx9XgZ1ZwrEzpofxPx06SQW6SolP0kjC5bZpWqLr4gYB 9lQNa/YC3A89M7Pa4fxRqsBoNEF4eOLsZcqggibTiF63rf04hSLcHav8MJ/RA5dQYxTF 7OEJ8wrl3PkY1ik8cuwm9GX70zMMI4WYiDVHdwXuPq3G1Yu5zepLMq7Gm345vWVCvl68 NXOw== X-Gm-Message-State: AOAM532JJBW1Un98maKrbhPsFDTs3PFATuhuk6AuIOWNywCPKjdVo+fq jLvgkXawcs/f0KFE64IdzRnfIZ8LXWhyDLj28Yc= X-Google-Smtp-Source: ABdhPJxfiyWH2esFyaSqxves8hUdvuvTtrWzVVh3ztWEq9vP9g7DuaXWWLhMEKG0PC9wgZ+vaOt4AhCpXqrpOBCtp40= X-Received: by 2002:a25:420b:: with SMTP id p11mr11325973yba.377.1629289256200; Wed, 18 Aug 2021 05:20:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Fan Date: Wed, 18 Aug 2021 20:20:45 +0800 Message-ID: Subject: Re: Window Function "Run Conditions" To: David Rowley Cc: Zhihong Yu , PostgreSQL Developers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi David: Thanks for the patch. On Wed, Aug 18, 2021 at 6:40 PM David Rowley wrote: > > On Tue, 17 Aug 2021 at 03:51, Zhihong Yu wrote: > > + if ((res->monotonic & MONOTONICFUNC_INCREASING) =3D=3D = MONOTONICFUNC_INCREASING) > > > > The above can be simplified as 'if (res->monotonic & MONOTONICFUNC_INCR= EASING) ' > > True. I've attached an updated patch. > > David Looks like we need to narrow down the situation where we can apply this optimization. SELECT * FROM (SELECT empno, salary, count(*) over (order by empno desc) as c , dense_rank() OVER (ORDER BY salary DESC) dr FROM empsalary) emp WHERE dr =3D 1; In the current master, the result is: empno | salary | c | dr -------+--------+---+---- 8 | 6000 | 4 | 1 (1 row) In the patched version=EF=BC=8C the result is: empno | salary | c | dr -------+--------+---+---- 8 | 6000 | 1 | 1 (1 row) --=20 Best Regards Andy Fan (https://www.aliyun.com/)