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 1kC3cp-0001iQ-1u for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Aug 2020 16:22: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 1kC3cm-0004no-W1 for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Aug 2020 16:22:40 +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 1kC3cm-0004mi-Ov for pgsql-hackers@lists.postgresql.org; Sat, 29 Aug 2020 16:22:40 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kC3cg-0005o6-84 for pgsql-hackers@lists.postgresql.org; Sat, 29 Aug 2020 16:22:39 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id AF6FD5F79F; Sat, 29 Aug 2020 12:22:31 -0400 (EDT) Date: Sat, 29 Aug 2020 12:22:31 -0400 From: Stephen Frost To: Andrey Lepikhov Cc: Bruce Momjian , Tom Lane , pgsql-hackers@lists.postgresql.org, Etsuro Fujita , Jeff Janes Subject: Re: Ideas about a better API for postgres_fdw remote estimates Message-ID: <20200829162231.GE29590@tamriel.snowman.net> References: <1155731.1593832096@sss.pgh.pa.us> <20200705170601.GD3125@tamriel.snowman.net> <1301903.1593970603@sss.pgh.pa.us> <20200705174817.GE3125@tamriel.snowman.net> <1309399.1593980722@sss.pgh.pa.us> <20200706141114.GF3125@tamriel.snowman.net> <1374896.1594047946@sss.pgh.pa.us> <20200706152828.GG3125@tamriel.snowman.net> <20200714013219.GD32422@momjian.us> <7a40707d-1758-85a2-7bb1-6e5775518e64@postgrespro.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wp04G5zzNHYrM8a5" Content-Disposition: inline In-Reply-To: <7a40707d-1758-85a2-7bb1-6e5775518e64@postgrespro.ru> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --wp04G5zzNHYrM8a5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings, * Andrey Lepikhov (a.lepikhov@postgrespro.ru) wrote: > During the implementation of sharding related improvements i noticed that if > we use a lot of foreign partitions, we have bad plans because of vacuum > don't update statistics of foreign tables.This is done by the ANALYZE > command, but it is very expensive operation for foreign table. > Problem with statistics demonstrates with TAP-test from the first patch in > attachment. Yes, the way we handle ANALYZE today for FDWs is pretty terrible, since we stream the entire table across to do it. > I implemented some FDW + pg core machinery to reduce weight of the problem. > The ANALYZE command on foreign table executes query on foreign server that > extracts statistics tuple, serializes it into json-formatted string and > returns to the caller. The caller deserializes this string, generates > statistics for this foreign table and update it. The second patch is a > proof-of-concept. Isn't this going to create a version dependency that we'll need to deal with..? What if a newer major version has some kind of improved ANALYZE command, in terms of what it looks at or stores, and it's talking to an older server? When I was considering the issue with ANALYZE and FDWs, I had been thinking it'd make sense to just change the query that's built in deparseAnalyzeSql() to have a TABLESAMPLE clause, but otherwise run in more-or-less the same manner as today. If we don't like the available TABLESAMPLE methods then we could add a new one that's explicitly the 'right' sample for an ANALYZE call and use that when it's available on the remote side. Not sure if it'd make any sense for ANALYZE itself to start using that same TABLESAMPLE code, but maybe? Not that I think it'd be much of an issue if it's independent either, with appropriate comments to note that we should probably try to make them match up for the sake of FDWs. > This patch speedup analyze command and provides statistics relevance on a > foreign table after autovacuum operation. Its effectiveness depends on > relevance of statistics on the remote server, but still. If we do decide to go down this route, wouldn't it mean we'd have to solve the problem of what to do when it's a 9.6 foreign server being queried from a v12 server and dealing with any difference in the statistics structures of the two? Seems like we would... in which case I would say that we should pull that bit out and make it general, and use it for pg_upgrade too, which would benefit a great deal from having the ability to upgrade stats between major versions also. That's a much bigger piece to take on, of course, but seems to be what's implied with this approach for the FDW. Thanks, Stephen --wp04G5zzNHYrM8a5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJfSoDHAAoJEO1sijiDR2RV2jgP/3xm+xO3RygPe2HAF44N1kk7 mpc1vyhBt6zk5IOTULdlkwDQq34Pc8sy3FVnoSmm6ZbgeJ2E9/HqQ+91O+q5BiKf CIJPI0JvEqErVe8DtpuHdzP3Q5BoHOn69g+MzQxFdUC1Lpa3Vqcisp7uGfTKLlRG lk6fgNy7mYCYUBLPPWr/UTdrPEGskLQRVeiFvk0z6DiUA+uWsVKXHGygbWh0td8i ePWP7eGgVeC57oSO363/ZS4M2ZZI+RNNLwRLtrUTdsOi9VEwqP566jM4+CzQkG9M pzNALzMxEW8T8Iuj/vnkhMIma7cw+J7ASd0qUC1ZQXqGi2TCxkIFd9cLGOCv88h9 DptUjMWKRzKGv81wdfg8qJZbQwpYVHTEV0fKhEV1IpZwsh1qP4A9DMY1Izzo/DCB KMGFtEo+79qLJUE8uNhALcOin0lS9AsKJz7a+0im0j7GoAYMY38hZZ2pBtCW3Hmo 0okSFkRO727irmrotvxsCS/4GzCeOVGpaIH9BuzjIBcZn5oyrqfSM6wSUCCB+Duh znBOoKBMwwx4cB9AE/EL4ljs1+tp2AzaSLPnLX1+VTN366mMv15BamN4cIOeToRx gVGDdvtyvTru1wHnLpOmH/0x8zddSV48dny2HFCdr5N+vUW/9zkhqk1rM58+NxXT sbHZQMsE8V2vXOJpMxFR =dN56 -----END PGP SIGNATURE----- --wp04G5zzNHYrM8a5--