pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
To: Stephen Frost <sfrost@snowman.net>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org, Etsuro Fujita <etsuro.fujita@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>
Subject: Re: Ideas about a better API for postgres_fdw remote estimates
Date: Sat, 29 Aug 2020 22:00:18 +0500
Message-ID: <93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru> (raw)
In-Reply-To: <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>
	<20200829162231.GE29590@tamriel.snowman.net>



On 8/29/20 9:22 PM, Stephen Frost wrote:
> 
>> 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 approach does not contradict your idea.  This is a lightweight 
opportunity to reduce the cost of analysis if we have a set of servers 
with actual versions of system catalog and fdw.
> 
>> 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.
> 

Thank you for this use case.

We can add field "version" to statistics string (btree uses versioning 
too). As you can see, in this patch we are only trying to get 
statistics. If for some reason this does not work out, then we go along 
a difficult route.

Moreover,  I believe this strategy should only work if we analyze a 
relation implicitly. If the user executes analysis explicitly by the 
command "ANALYZE <relname>", we need to perform an fair analysis of the 
table.

-- 
regards,
Andrey Lepikhov
Postgres Professional





view thread (25+ messages)  latest in thread

Message-ID: <93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru>
Permalink:  ../93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru/
Also on:    postgresql.org/message-id/93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: a.lepikhov@postgrespro.ru, sfrost@snowman.net, bruce@momjian.us, tgl@sss.pgh.pa.us, etsuro.fujita@gmail.com, jeff.janes@gmail.com
  Subject: Re: Ideas about a better API for postgres_fdw remote estimates
  In-Reply-To: <93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru>
  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> <20200829162231.GE29590@tamriel.snowman.net> <93c0dcb8-59fd-69e4-edcf-e20a4542ddb3@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox