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 1mGbed-0006ea-Kt for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Aug 2021 06:35:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mGbeb-0003Hb-6F for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Aug 2021 06:35:53 +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 1mGbea-0003HR-Sb for pgsql-hackers@lists.postgresql.org; Thu, 19 Aug 2021 06:35:52 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mGbeU-0006kK-Ht for pgsql-hackers@lists.postgresql.org; Thu, 19 Aug 2021 06:35:52 +0000 Received: by mail-pl1-x62a.google.com with SMTP id u15so3289818plg.13 for ; Wed, 18 Aug 2021 23:35:45 -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=8TtR744g6UHSOPEBDWmnwX+gLe/ZCQsVv264fy/vqak=; b=cegMtPcL+rnWR41qlhiIiWhWODBS/dVV9Ksf31JFwJFaY4jlB4bWKjyV2s8YxJdSYu fOhO+gquwln7GeWeXVUHq4Df18OzTsnRLOORfLVRbQuVkpcPlcwKCubmaAU0wBmWoJOn 5CgHdpzecG6zz8NPDdmqjNq5ZGs+Brl/b85g1R/Nxh5+SGj4BEOpC/f2Pxa1zs0nhhHz fTkzt8/E8LbfY6WoSx7TI6GihK5ipzerwtZ34fRxtZpuKt04Lrwe5cgn18litDlmh2pZ fll0T6dhPyblZCVMFMXfObXPsBSEag4955uZ3HNHwLmHdMbw6DrG7EBSVVu2XQoLntNu tc+Q== 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=8TtR744g6UHSOPEBDWmnwX+gLe/ZCQsVv264fy/vqak=; b=PAoRBtZw/aB+jOO0ArX06b5gnyGzxFY0+2bntqu2auG9Q9NkyRFv/SK+Fh13oLhtFH 8rvdSD/6jMisGBvWpdU0wt0/HLprNsuZGIqwtacYeZ8iGooxuFvmj1rsSQnhWXeyopPU 6Oj093cgML2I9H/zlbXE/4pfKb5Y9R9+5ZE50G3KUEsd/dy07ZbnCV3UrwSpbKHpguIR GGIINQ73v4ZHKQTL7Q7bJBUxVG65mpU10Bm1N22ChXrGK1i1fV1V841y9TfL2RlhVR5B O9v6jFnyOQEUguKclW3GofYt81JiYdFQ3NG3mz6xYYnQO1RRDGX91CATzd/Zv+C9fw5E LJRA== X-Gm-Message-State: AOAM531C4dFAL9Keu/USVSyQ6K1fo2UPz74g7+NlvxM/q/JuOevrFvdh rXPVCOjxGfbd5bVvAkgMQwnhmWXRIyFthW6vq7w= X-Google-Smtp-Source: ABdhPJxbGCx7w7hH8Ps8zvIqCasLGgK8oLdJ+IUZc7z1SrXHz6VpdFSriosjmJ04SxBjgz4rdu+YVtRV6oKCeuN7BP4= X-Received: by 2002:a17:902:ecc9:b0:12d:a202:76f4 with SMTP id a9-20020a170902ecc900b0012da20276f4mr10391553plh.34.1629354944253; Wed, 18 Aug 2021 23:35:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Thu, 19 Aug 2021 18:35:27 +1200 Message-ID: Subject: Re: Window Function "Run Conditions" To: Andy Fan 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 On Thu, 19 Aug 2021 at 00:20, Andy Fan wrote: > In the current master, the result is: > > empno | salary | c | dr > -------+--------+---+---- > 8 | 6000 | 4 | 1 > In the patched version=EF=BC=8C the result is: > > empno | salary | c | dr > -------+--------+---+---- > 8 | 6000 | 1 | 1 Thanks for taking it for a spin. That's a bit unfortunate. I don't immediately see how to fix it other than to restrict the optimisation to only apply when there's a single WindowClause. It might be possible to relax it further and only apply if it's the final window clause to be evaluated, but in those cases, the savings are likely to be much less anyway as some previous WindowAgg will have exhausted all rows from its subplan. Likely restricting it to only working if there's 1 WindowClause would be fine as for the people using row_number() for a top-N type query, there's most likely only going to be 1 WindowClause. Anyway, I'll take a few more days to think about it before posting a fix. David