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 1l4mjE-00044Y-IN for pgsql-general@arkaria.postgresql.org; Wed, 27 Jan 2021 15:27:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l4mjD-0002jx-2D for pgsql-general@arkaria.postgresql.org; Wed, 27 Jan 2021 15:27:31 +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 1l4mjC-0002jp-Qc for pgsql-general@lists.postgresql.org; Wed, 27 Jan 2021 15:27:30 +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 1l4mjA-0000vP-Ix for pgsql-general@lists.postgresql.org; Wed, 27 Jan 2021 15:27:29 +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 10RFRR1D2391647; Wed, 27 Jan 2021 10:27:27 -0500 From: Tom Lane To: Kai Daguerre cc: pgsql-general@lists.postgresql.org Subject: Re: Custom FDW - the results of a nested query/join not being passed as qual to the outer query In-reply-to: References: Comments: In-reply-to Kai Daguerre message dated "Wed, 27 Jan 2021 13:08:47 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2391645.1611761247.1@sss.pgh.pa.us> Date: Wed, 27 Jan 2021 10:27:27 -0500 Message-ID: <2391646.1611761247@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kai Daguerre writes: > We often have virtual tables where a list operation is not viable/possible > without providing quals. For example we have implemented a 'whois' table, > which will retrieve whois information for specified domains. It is clearly > not practical to do an unqualified 'list' of *all* domains. In that case you're going to have to resign yourself to some queries failing. This is unavoidable, consider "select * from whois". But just because the query has a WHERE condition doesn't mean that a useful restriction clause can be extracted for any particular table. I think the best you can do is (1) fail at runtime if there's no qual and (2) at plan time, return an extremely high cost estimate for a qual-less scan, in hopes of discouraging the planner from choosing that. (Instead of (2), you could perhaps not generate a scan path at all, but that's likely to lead to an unintelligible error message.) Perhaps you should rethink whether you really want a foreign table rather than a set-returning function. With the SRF approach it's automatic that the user must supply the restricting argument(s) you need. regards, tom lane