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 1nvVJ9-0006V7-I3 for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 02:39:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nvVJ8-00038L-G7 for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 02:39:02 +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 1nvVJ8-00038C-6H for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 02:39:02 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nvVJ4-0008Py-Vd for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 02:39:01 +0000 Received: by mail-oi1-x234.google.com with SMTP id r206so5337549oib.8 for ; Sun, 29 May 2022 19:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6RboOiiQhsqtX28gvm/rOpBypiqpS3Q7dB8KNK+/Tm8=; b=lyoX2Kr/V9nDhXrmTfvyH5/KxYGF4bB/WUwG6ji92agAdSJP/a2Ip2andmRpd17MYp ZNkSEsMHUgZ9LTkt+j0eWtI7J6kzoqEYZHYSkPQOgGw5udhgUxJ8BYo/GWBtXE8H+7rs Bhkveel3liCvrzWashx4mRYVWbTKz9eJFzNzWoruqWs107nVFt0CpeRftnNsbSf0j6sD sRfZuFM8SjMgXfGH6F1roJGvLImbjuzkTrSmBpnxChjL3elmj1vy+V98rrNFsoHoH/6j FiCl4sZyGRj6TubHw4R60ssL9TNAr0b/mmAYB5/jBIE9KmPyufUKyiKkt+Yr0GYzAXEE blag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6RboOiiQhsqtX28gvm/rOpBypiqpS3Q7dB8KNK+/Tm8=; b=UmyG+7XNI6FOAPC64bNELLMjMCEaRxm0ewNFKrmnOh1rXNZoWZD7hQ2Pm89xcwtkq7 wIWXUYaOHUQyOzLHw1AtUgDer6lcRLieqLW6ipsUg9pmHn9H5pB/R6oTFpL0lRDpaaKF lJBrYCtj3hZ9ryAWjg3Uh/rDQhJIO4dsaP9mnd72SSIJh3aQ4gEueDIaDUVLlIe0O2qP f2baIsY/Aqx73u8s9Qoua71ATMnOFrwU7nyMHYtU2y2cLnIYQ4J8WF06AImj+wtItc1m qIXNnZGU+q1ahFXF3NgPjhyVObHWhJqwYyDJ2L8OCaeHXPfb5vFWtrAdWrlL6lPe59MC kPXw== X-Gm-Message-State: AOAM532qMlPJDM4XA6QzGUHgBEZflNe5xI4Bd8pFic8RCqvuhrvo/Xg3 Me/8Tj5Dn1guPuKosNQR06qlrJsXRYYXVE+kDx8= X-Google-Smtp-Source: ABdhPJxG96t8FD/0P8c+qDUuSCCmLNV0+MFuWaEt6uXesbCMCpQbBrIECk85/fpz3XgWAr7lina9KWkHHa/2LVHboNw= X-Received: by 2002:a05:6808:13ce:b0:328:da83:aba3 with SMTP id d14-20020a05680813ce00b00328da83aba3mr8920630oiw.265.1653878336945; Sun, 29 May 2022 19:38:56 -0700 (PDT) MIME-Version: 1.0 References: <17502-281a7aaacfaa872a@postgresql.org> <3722616.1653877139@sss.pgh.pa.us> In-Reply-To: <3722616.1653877139@sss.pgh.pa.us> From: David Rowley Date: Mon, 30 May 2022 14:38:43 +1200 Message-ID: Subject: Re: BUG #17502: View based on window functions returns wrong results when queried To: Tom Lane Cc: =?UTF-8?Q?Daniel_Farka=C5=A1?= , Magnus Hagander , PostgreSQL mailing lists Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 30 May 2022 at 14:19, Tom Lane wrote: > > David Rowley writes: > > The problem seems to be down to the fact that > > remove_unused_subquery_outputs() does not check if the to-be-removed > > target entry references WindowClauses which contain set-returning > > functions. > > I was sort of wondering why we allow SRFs in this context in the > first place. The results don't seem terribly well-defined to me. > In particular, a WindowFunc invocation is not supposed to change the > number of rows in the query result, and yet this one is doing so. That would certainly be an easier fix for the reported problem. Do you think it would fly to add such a restriction in the backbranches? David