Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erCO9-0001X4-PN for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Mar 2018 00:48:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erCO8-0005QC-S2 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Mar 2018 00:48:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erCO8-0005Q1-H5 for pgsql-hackers@lists.postgresql.org; Thu, 01 Mar 2018 00:48:00 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erCO2-0007lF-SJ for pgsql-hackers@postgresql.org; Thu, 01 Mar 2018 00:47:56 +0000 Received: by fetter.org (Postfix, from userid 1001) id D8E9041785; Thu, 1 Mar 2018 01:47:52 +0100 (CET) Date: Thu, 1 Mar 2018 01:47:52 +0100 From: David Fetter To: Euler Taveira Cc: pgsql-hackers Subject: Re: row filtering for logical replication Message-ID: <20180301004752.GG25493@fetter.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Feb 28, 2018 at 08:03:02PM -0300, Euler Taveira wrote: > Hi, > > The attached patches add support for filtering rows in the publisher. > The output plugin will do the work if a filter was defined in CREATE > PUBLICATION command. An optional WHERE clause can be added after the > table name in the CREATE PUBLICATION such as: > > CREATE PUBLICATION foo FOR TABLE departments WHERE (id > 2000 AND id <= 3000); > > Row that doesn't match the WHERE clause will not be sent to the subscribers. > > Patches 0001 and 0002 are only refactors and can be applied > independently. 0003 doesn't include row filtering on initial > synchronization. > > Comments? Great feature! I think a lot of people will like to have the option of trading a little extra CPU on the pub side for a bunch of network traffic and some work on the sub side. I noticed that the WHERE clause applies to all tables in the publication. Is that actually the right thing? I'm thinking of a case where we have foo(id, ...) and bar(foo_id, ....). To slice that correctly, we'd want to do the ids in the foo table and the foo_ids in the bar table. In the system as written, that would entail, at least potentially, writing a lot of publications by hand. Something like WHERE ( (table_1,..., table_N) HAS (/* WHERE clause here */) AND (table_N+1,..., table_M) HAS (/* WHERE clause here */) AND ... ) could be one way to specify. I also noticed that in psql, \dRp+ doesn't show the WHERE clause, which it probably should. Does it need regression tests? Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate