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 1k8sTH-00071S-Jm for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Aug 2020 21:51:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k8sTG-0000Bf-Gv for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Aug 2020 21:51:42 +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 1k8sTG-0000BY-AZ for pgsql-bugs@lists.postgresql.org; Thu, 20 Aug 2020 21:51:42 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k8sT9-00025R-RS for pgsql-bugs@lists.postgresql.org; Thu, 20 Aug 2020 21:51:41 +0000 Received: from [192.168.127.1] (port=26810 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1k8sT7-0000oL-0z; Thu, 20 Aug 2020 21:51:33 +0000 Received: from localhost ([127.0.0.1]:10699 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1k8sT6-0000QQ-Fh; Thu, 20 Aug 2020 21:51:32 +0000 From: Andrew Gierth To: Tom Lane Cc: David Rowley , pavelsivash@gmail.com, PostgreSQL mailing lists Subject: Re: BUG #16585: Wrong filtering on a COALESCE field after using GROUPING SETS In-Reply-To: <1750212.1597958727@sss.pgh.pa.us> (Tom Lane's message of "Thu, 20 Aug 2020 17:25:27 -0400") Message-ID: <87tuwxrnzm.fsf@news-spur.riddles.org.uk> References: <16585-9d8c340d23ade8c1@postgresql.org> <87mu2qixx5.fsf@news-spur.riddles.org.uk> <1750212.1597958727@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Thu, 20 Aug 2020 22:51:32 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: Tom> As a stopgap measure, I think what we have to do is teach Tom> check_output_expressions that subquery output columns are unsafe Tom> to reference if they are not listed in all grouping sets (do I Tom> have that condition right?). Unless I'm missing something, it should be safe to reference output columns that are not mentioned in any grouping set, or which are mentioned in all grouping sets (after all expansions); but unsafe to reference columns mentioned in some grouping sets but not others (since these will be forced to null in the output for the sets in which they don't appear). -- Andrew (irc:RhodiumToad)