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 1pDq4X-0002lj-St for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 17:00:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pDq3X-0005II-0W for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 16:58:59 +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 1pDq3W-0005I9-Nw for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 16:58:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pDq3U-00077k-H5 for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 16:58:58 +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 306GwqoN3013666; Fri, 6 Jan 2023 11:58:52 -0500 From: Tom Lane To: Tomas Vondra cc: James Finnerty , pgsql-hackers@lists.postgresql.org Subject: Re: postgres_fdw: using TABLESAMPLE to collect remote sample In-reply-to: <4ee816f5-6146-7745-a6b4-f38a1b24105a@enterprisedb.com> References: <151e835f-55d6-ddbc-b5b4-07ee606aba44@enterprisedb.com> <03182011-10a4-97b4-7c70-d99aa1c11eed@enterprisedb.com> <167112207543.1120.12195641719862911275.pgcf@coridan.postgresql.org> <3377008.1671122816@sss.pgh.pa.us> <6da357b0-fdd3-095d-a06c-87666f4a5a8c@enterprisedb.com> <951485.1672461744@sss.pgh.pa.us> <233ee0b3-4da0-3370-cd0b-1b8528851ddd@enterprisedb.com> <1040922.1672507431@sss.pgh.pa.us> <3d719e62-64d2-5184-eebf-6128bcb398e2@enterprisedb.com> <2813656.1672952711@sss.pgh.pa.us> <3e8cca01-f102-d4b9-abe9-ed7b5e938323@enterprisedb.com> <2837327.1672955815@sss.pgh.pa.us> <4ee816f5-6146-7745-a6b4-f38a1b24105a@enterprisedb.com> Comments: In-reply-to Tomas Vondra message dated "Fri, 06 Jan 2023 15:40:36 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3013664.1673024332.1@sss.pgh.pa.us> Date: Fri, 06 Jan 2023 11:58:52 -0500 Message-ID: <3013665.1673024332@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > The one difference is that I realized the relkind check does not > actually say we can't do sampling - it just means we can't use > TABLESAMPLE to do it. We could still use "random()" ... > Furthermore, I don't think we should silently disable sampling when the > user explicitly requests TABLESAMPLE by specifying bernoulli/system for > the table - IMHO it's less surprising to just fail in that case. Agreed on both points. This patch looks good to me. > Of course, all relkinds that don't support TABLESAMPLE currently have > reltuples value that will disable sampling anyway (e.g. views have -1). > So we won't actually fallback to random() anyway, because we can't > calculate the sample fraction. > That's a bit annoying for foreign tables pointing at a view, which is a > more likely use case than table pointing at a sequence. Right, that's a case worth being concerned about. > But I realized we could actually still do "random()" sampling: > SELECT * FROM t ORDER BY random() LIMIT $X; Hmm, interesting idea, but it would totally bollix our correlation estimates. Not sure that those are worth anything for remote views, but still... regards, tom lane