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 1pEAzg-0007nP-Iz for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Jan 2023 15:20:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pEAzf-0005Ml-8c for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Jan 2023 15:20:23 +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 1pEAze-0005LX-VY for pgsql-hackers@lists.postgresql.org; Sat, 07 Jan 2023 15:20:22 +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 1pEAzY-0005vo-MR for pgsql-hackers@lists.postgresql.org; Sat, 07 Jan 2023 15:20:21 +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 307FKAE13447193; Sat, 7 Jan 2023 10:20:10 -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: <560c80fc-823e-418d-280e-e0c7c0dad59b@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> <3013665.1673024332@sss.pgh.pa.us> <4daee204-341f-d413-fa93-29f603f61da8@enterprisedb.com> <560c80fc-823e-418d-280e-e0c7c0dad59b@enterprisedb.com> Comments: In-reply-to Tomas Vondra message dated "Sat, 07 Jan 2023 15:07:58 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3447191.1673104810.1@sss.pgh.pa.us> Date: Sat, 07 Jan 2023 10:20:10 -0500 Message-ID: <3447192.1673104810@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > However, maybe views are not the best / most common example to think > about. I'd imagine it's much more common to reference a regular table, > but the table gets truncated / populated quickly, and/or the autovacuum > workers are busy so it takes time to update reltuples. But in this case > it's also quite simple to fix the correlation by just ordering by ctid > (which I guess we might do based on the relkind). > There's a minor issue with partitioned tables, with foreign partitions > pointing to remote views. This is kinda broken, because the sample size > for individual relations is determined based on relpages. But that's 0 > for views, so these partitions get ignored when building the sample. But > that's a pre-existing issue. I wonder if we should stop consulting reltuples directly at all, and instead do "EXPLAIN SELECT * FROM remote_table" to get the remote planner's estimate of the number of rows involved. Even for a plain table, that's likely to be a better number. regards, tom lane