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 1p3e4e-00061m-76 for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2022 14:10:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3e3d-0008RF-RA for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2022 14:08:57 +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 1p3e3d-0008R6-HT for pgsql-bugs@lists.postgresql.org; Fri, 09 Dec 2022 14:08:57 +0000 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3e3X-0002jF-4Y for pgsql-bugs@lists.postgresql.org; Fri, 09 Dec 2022 14:08:56 +0000 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1433ef3b61fso5734232fac.10 for ; Fri, 09 Dec 2022 06:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/I4Q2MYwh3s4/Dv4IA9bX3bdSXvTG/WpSJ3kJ2R+wlY=; b=lKB3Huxy9jdeLINF7ycvk4uuS09ziVefHOYq1KH29XO9vLIRrms5yjZcTz1enZzUsC Ta4R0tekhmhD8v7hjA0+VTKWZIuGMaBwQ95/hvzZKrFqKyLgJEj4avLd78wbQUC1GNfj elxWEE9SoZZ1edEOsNFUZ36xDww1ycgs1TvcG7hkPdj7nyGj0ReBjbEHxaJo9vllzziO GUC6hLKKuAFNQL1GFQUDn7SYPNQc9DZ393/7gyq9KHO/PSRFl7Px4tsL/gMvuPG8VS0z YsC3lPPW1vcC3m/xl3VgMUnE7cBDn3BUN/BAyfZqnFPcK9MyvHbXmKD7CfNMPIUbL/5s 17MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/I4Q2MYwh3s4/Dv4IA9bX3bdSXvTG/WpSJ3kJ2R+wlY=; b=UsiQhaeSuAXLuU9UJqbdgoafDRm52vBcgqLVyYBDqlysrnOj8GeR4JnGGSN0GS/t51 /gyjIJ5vYoMjTR0cFNRX0nuzBdBcsyctWetjxYrYKpPQO5IW7nzS/6u4S+kCrDDvndbZ UtamLfXY/oTmvJAgA6DXUr1P1V879VO8ltelnQoD0GS7RoCgAn5xkGe68Db0mL4eHyvF bza0bJLBPwBFIV+MtGRqamstmiQeQPVcC4yn7r/Z5+xv4Fd4nCTmn69ej8cqZxtfCoEk LkgLCO+2BzUmmg1QQM/ZUxB2IaqvNCTk0dEHElHKZwpKBCrJLfWnbxRGy4JwC+tobdju 25kg== X-Gm-Message-State: ANoB5pkYw0ZPCe2pLt1m3YRLQD0FgaGLlvFs3Skzx62vMVbbYidO0196 Ms+4RjaDSmEFtzpPFy3Bmr2eaY56dGW+NQeyqP40LR/tf5Y= X-Google-Smtp-Source: AA0mqf58IaXitg323XgAwZYeEOaBet4wPSIwf1131Mwkr0rpFgMb7OrSv++/uQitVwVuFX/IRsVmiGqRYK2ucaaNb2o= X-Received: by 2002:a17:90a:668d:b0:21a:1d94:56a0 with SMTP id m13-20020a17090a668d00b0021a1d9456a0mr5465185pjj.210.1670594492687; Fri, 09 Dec 2022 06:01:32 -0800 (PST) MIME-Version: 1.0 References: <17709-4f557160e3e8ee9a@postgresql.org> In-Reply-To: From: Richard Guo Date: Fri, 9 Dec 2022 22:01:21 +0800 Message-ID: Subject: Re: BUG #17709: Regression in PG15 with window functions - "WindowFunc not found in subplan target lists" To: David Rowley Cc: makhmutov@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000004ceb5e05ef659757" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004ceb5e05ef659757 Content-Type: text/plain; charset="UTF-8" On Fri, Dec 9, 2022 at 7:53 PM David Rowley wrote: > The additional thing that seems to cause the reported error is that > once the subquery is pulled up, the run condition also needs a round > of constant folding done. See subquery_planner() around line 827. The > problem is that the target list's WindowFunc ends up with count(1) > over .., but the run condition's one is left as count(case 1 when 1 > then 1 else null end), which preprocess_expression() will fold into > the same as what's in the target list. Yes exactly. That's what we also have to do. I was debugging with a simplified version of the query with the WindowFunc as count(t1.a) over (...) and did not realize constant folding is also needed for the runCondition. > I'm now wondering if WindowClause.runCondition should be of type Node > * instead of List *. I'd have imagined I should be passing the type of > EXPRKIND_QUAL to preprocess_expression's type, but canonicalize_qual() > does not like Lists. I'm not sure about this. From how the runCondition is constructed in find_window_run_conditions, it seems there is no need to canonicalize it. Thanks Richard --0000000000004ceb5e05ef659757 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Fri, Dec 9, 2022 at 7:53 PM David Rowl= ey <dgrowleyml@gmail.com>= wrote:
The additional thing that seems to cause the reported error is that
once the subquery is pulled up, the run condition also needs a round
of constant folding done. See subquery_planner() around line 827.=C2=A0 The=
problem is that the target list's WindowFunc ends up with count(1)
over .., but the run condition's one is left as count(case 1 when 1
then 1 else null end), which preprocess_expression() will fold into
the same as what's in the target list.
=C2=A0
Yes exactly. That's what we also have to do.=C2=A0 I was debugging wi= th a
simplified version of the query with the WindowFunc as count(t1.a) = over
(...) and did not realize constant folding is also needed for therunCondition.
=C2=A0
I'm now wondering if WindowClause.runCondition should be of type Node * instead of List *. I'd have imagined I should be passing the type of<= br> EXPRKIND_QUAL to preprocess_expression's type, but canonicalize_qual()<= br> does not like Lists.
=C2=A0
I'm not sure abo= ut this.=C2=A0 From how the runCondition is constructed in
find_window_r= un_conditions, it seems there is no need to canonicalize
it.

Than= ks
Richard
--0000000000004ceb5e05ef659757--