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 1oJF3m-0004nj-1X for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Aug 2022 14:09:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJF3k-00022U-LW for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Aug 2022 14:09:16 +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 1oJF3k-0001xR-Ch for pgsql-bugs@lists.postgresql.org; Wed, 03 Aug 2022 14:09:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJF3i-0001AF-5s for pgsql-bugs@lists.postgresql.org; Wed, 03 Aug 2022 14:09:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 273E9Ccb2967746; Wed, 3 Aug 2022 10:09:12 -0400 From: Tom Lane To: Richard Guo cc: Martijn van Oosterhout , PostgreSQL mailing lists Subject: Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY In-reply-to: References: <17564-c7472c2f90ef2da3@postgresql.org> <2184335.1659392231@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Wed, 03 Aug 2022 15:45:19 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2967744.1659535752.1@sss.pgh.pa.us> Date: Wed, 03 Aug 2022 10:09:12 -0400 Message-ID: <2967745.1659535752@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > - if (IS_SRF_CALL((Node *) em->em_expr)) > + if (expression_returns_set((Node *) em->em_expr)) Yeah. I think we need to go further: placed in optimizer.h as it is, IS_SRF_CALL is just an invitation to writing broken code. I think the calls in tlist.c are legit because that code is precisely concerned with breaking down nests of SRFs; but everywhere else, if you write IS_SRF_CALL you're doing it wrong. We should take that macro out of the header altogether. I kind of wonder whether IS_SRF_CALL is a good idea at all. It'd be more maintainable to have an expression_returns_set_one_level, or something like that, placed beside expression_returns_set. regards, tom lane