Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gPy0Y-0008Di-5C for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Nov 2018 23:03:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gPy0V-0005st-Hs for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Nov 2018 23:03:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gPy0V-0005r0-0W for pgsql-hackers@lists.postgresql.org; Thu, 22 Nov 2018 23:03:35 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gPy0Q-0005of-TO for pgsql-hackers@postgresql.org; Thu, 22 Nov 2018 23:03:33 +0000 Received: by mail-wr1-x444.google.com with SMTP id q18so10620942wrx.9 for ; Thu, 22 Nov 2018 15:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DOxQhvhxDNLEfoW18palxLfkeqizqI+i3ucADsjUuTo=; b=uOjCZEsj5muOJWmx9/Z9OgBn1nKWlcMU5+uxupsR2Tn91tV/qq5Ki1SaQQI6reWV8v WwCMzslASkbWp06GgNyxZGbTz9BwcfIYRy5N3+q9C3frWTRdKyMb0bIOHiW1h68OviHE Dqd8WlRswnAVZKaVf3h1BCxStZCmlcZXYWCRT98wKY/aJA0dUdQyhbwAIXzv+Ig/p6Cb nt20WRGg7cdEHWPxXvZk3v9LQwwLRge3i6zU/9jRFt4nVkEnyVwjA1yAKfWNc8zZOMUg whgZYdKuNiurDg1kS/8ybPXHqQw4kYxy/cUmF6Ln+Pp3fnkOOd7IxPobX+GhkJk7OpAD uqEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=DOxQhvhxDNLEfoW18palxLfkeqizqI+i3ucADsjUuTo=; b=eNtyLApvmWkHaItiPSx4JHFJkrxCLvMO+t9PzqDELonPtkm+lKJen7cGkThxSzz4nY GzgTrbCz01yrvCf+F/lImu3xI93TOnYcWwwe5gTT+rDCYuYXb/ngdboObLkO7dJ1kK6/ FfkjQAqVBaHEaYoW/gaspNyQhiKyFehjGW/+Yab8ffXG7eDzjdC3OUX4L/k3zMdhKwHG /k0qY20w1o/2D7OqFJ4fOAs/98VuE+xgN/LPn/8cdnDJrH6+gXBS708h0UFQ2Ki7OiNh y1/SquuSEof2nw4XYmTeK3dYiX2+6w4S+wuyevwzi0lW2ZzOSRsgRvDALhEsibh2bd22 FJjA== X-Gm-Message-State: AA+aEWaESW6CsU87E/g3K5a3OQUTAA8PSFC3E0yAK5WsL2KRcxUiNnvL MeYfi16zh8HIjEkpNNw7CDFsG4VjRIgiTg== X-Google-Smtp-Source: AFSGD/Vw7L8PQ7USf3ov++T3V+ioxlEldviELAvsqVUw0zJLs+bvgbGRLDTmRcyE4Jh1x1xZLJhroA== X-Received: by 2002:adf:d112:: with SMTP id a18mr12038332wri.17.1542927809194; Thu, 22 Nov 2018 15:03:29 -0800 (PST) Received: from [192.168.0.99] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id o8sm14429459wrx.15.2018.11.22.15.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:03:28 -0800 (PST) Subject: Re: row filtering for logical replication To: Euler Taveira , pgsql-hackers Cc: Suzuki Hironobu References: From: Petr Jelinek Openpgp: preference=signencrypt Autocrypt: addr=petr.jelinek@2ndquadrant.com; prefer-encrypt=mutual; keydata= xsFNBFawwSABEAC45Vua8rSggpM2kkMMmoOHz51a+fi3OXFfnrStVh80pM2/J9nSzjrIKQKf H5PtRnoYzSKnoUDoLOkLwDYitK3HzUUWXma+AWAqef2Y0GSZ7A3jJkD+JHOfkpS1CIpkEB/e WjA8Wqegwzc/OEE5111/l0Q1e6jxgZI86h8MMnm35Of1Y6Lz4kqWCyxHhaTJKTCkq66ICQ2C VJkbvuUoEE+Hr/I38dPHTAqIlCnycVnJPLHBQ/UYGHR/USF8qI/qJJx6tJcNAEqz69QZ/VlY 31UyJHdYe5NtBVz+rYZCOVWfpe3crbHuq9FjAPT+xcZefdxridmMKuW8eBmmXI9iZ3EG+X8J IsdLWL8QoqW0lnO1otYz1QDjdOvbEpq+u5/TAU8pgtaYH2J+6/GaQ6hMLyLBkaIAtnqlLCzq pxXcxMsFT14P5/rZA7EbBI8RS1ZIWJBlS2oO+dtVuENLJUC0SpptaRyn/uyOIopt7hSmBekL SzFnet7P9qofFJY+fQEz84v0G1gvwonHGHiCGgLpbMdPtnfPzda1aiTURvvOD7w/RmX1/ogk TqSGO4ejVNO/28QYouxmxzy8jbbIEiLCbHpLR/M/TvYHHPURxcx+MxVl3G+d/4Ihy4abxOdW pe9zLIcVMvqiUFQO28/79Gfhb7G4K+L21ORB82QYkzm3M7ebXQARAQABzSNQZXRyIEplbMOt bmVrIDxwam1vZG9zQHBqbW9kb3MubmV0PsLBgAQTAQoAKgIbAwUJBaOagAULCQgHAwUVCgkI CwUWAgMBAAIeAQIXgAUCVrDBqwIZAQAKCRBci2l0giH4y/QJEACfiLHyvxlwMvo3Y88Qa9QI i7Hu3ZW+xxojojdRd7do0nBnf2a4YstD9u6ZOLJx4f5Ijb/8LxY10N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MIPj TxnClKiecuBQQPzMaG0jTmK0lis6rO0nIXrCwca8e/3Xzvi7sykOdcz9t4ef8HrDCCkG0yDO o8qHy1e7EtmJD7kWffIXZMt4TZVxpiOqgWtv+heJAfmqzr8pkNLUubmgvNdnakXJOJT41Lui 50C5OhpU9mfFCIDOeZXTQLsHA4KYaL8W/qcjv/YDmvpJtnK24y6tByWuTu7r/SMAEQEAAcLB ZQQYAQoADwUCVrDBIAIbDAUJBaOagAAKCRBci2l0giH4yyWpD/91jd4BMN2CDYqLtU7kaoAa aXnRVpf0z+R8rJ4LZJX1UNbHjsdClMQLfdBuZeDsdYar4iMfwScz6fiCiRwaRpr3XT6znaM0 wba6fjzEqVSHr3WB1jrb/TMiNaNgQJaRPhI5C7VsLuPrv5/L8gFmyjl712q7F3busGFBKrjK qTESMu+sHNvVeC3QyBFCe2fudbAJdaaRsUoTbAZYiowVoQHOow8eBoWY+RzQoYGuw1fls5Ck 85N73pYHXzjfk1s49sDKTYI263h9wbGGA234biHRI3NQN6sSYWRr/u5GOwTm/tzyadRj0pnZ S6KyLSEL4qx8jiyniD/XLoftlvR4YWQ0BXveEElx2n3TThLL1cVtOI4qE9BZKm32euBqwLta k9Jc659hmZB9E9aWLo8KcLjngwqSZupoHRPZ3yAlgZkpDoTIZpMCGxGEuuxgnosRbNpOJ1fE nNXenYYfi87tHRUCRKeHhoKkfGZEgC9zv9Y97j75npqV2tQyh4fNQT1tGdBigtvzI4nHM1/1 PLJtJBdRHucP76vUH9RlP9EE/Sg5DFQqsfSYPqxLW9r+ZfSEeT0APdz7TQC9MzNzUhyXvA5a RQQCRMXKbGaYhKkYEYiYOGqtTxN+PmyvNUBmFEcagBX2TXqEkgnI6zOnN13mB4SihJ2lne2r 9RNiPYs/hmRxYg== Message-ID: <7106a0fc-8017-c0fe-a407-9466c9407ff8@2ndquadrant.com> Date: Fri, 23 Nov 2018 00:03:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/11/2018 01:29, Euler Taveira wrote: > Em qua, 28 de fev de 2018 às 20:03, Euler Taveira > escreveu: >> The attached patches add support for filtering rows in the publisher. >> > I rebased the patch. I added row filtering for initial > synchronization, pg_dump support and psql support. 0001 removes unused > code. 0002 reduces memory use. 0003 passes only structure member that > is used in create_estate_for_relation. 0004 reuses a parser node for > row filtering. 0005 is the feature. 0006 prints WHERE expression in > psql. 0007 adds pg_dump support. 0008 is only for debug purposes (I'm > not sure some of these messages will be part of the final patch). > 0001, 0002, 0003 and 0008 are not mandatory for this feature. > > Comments? > Hi, I think there are two main topics that still need to be discussed about this patch. Firstly, I am not sure if it's wise to allow UDFs in the filter clause for the table. The reason for that is that we can't record all necessary dependencies there because the functions are black box for parser. That means if somebody drops object that an UDF used in replication filter depends on, that function will start failing. But unlike for user sessions it will start failing during decoding (well processing in output plugin). And that's not recoverable by reading the missing object, the only way to get out of that is either to move slot forward which means losing part of replication stream and need for manual resync or full rebuild of replication. Neither of which are good IMHO. Secondly, do we want to at least notify user on filters (or maybe even disallow them) with combination of action + column where column value will not be logged? I mean for example we do this when processing the filter against a row: > + ExecStoreHeapTuple(new_tuple ? new_tuple : old_tuple, ecxt->ecxt_scantuple, false); But if user has expression on column which is not part of replica identity that expression will always return NULL for DELETEs because only replica identity is logged with actual values and everything else in NULL in old_tuple. So if publication replicates deletes we should check for this somehow. Btw about code (you already fixed the wrong reloid in sync so skipping that). 0002: > + for (tupn = 0; tupn < walres->ntuples; tupn++) > { > - char *cstrs[MaxTupleAttributeNumber]; > + char **cstrs; > > CHECK_FOR_INTERRUPTS(); > > /* Do the allocations in temporary context. */ > oldcontext = MemoryContextSwitchTo(rowcontext); > > + cstrs = palloc(nfields * sizeof(char *)); Not really sure that this is actually worth it given that we have to allocate and free this in a loop now while before it was just sitting on a stack. 0005: > @@ -654,5 +740,10 @@ rel_sync_cache_publication_cb(Datum arg, int cacheid, uint32 hashvalue) > */ > hash_seq_init(&status, RelationSyncCache); > while ((entry = (RelationSyncEntry *) hash_seq_search(&status)) != NULL) > + { > entry->replicate_valid = false; > + if (list_length(entry->row_filter) > 0) > + list_free(entry->row_filter); > + entry->row_filter = NIL; > + } Won't this leak memory? The list_free only frees the list cells, but not the nodes you stored there before. Also I think we should document here that the expression is run with the session environment of the replication connection (so that it's more obvious that things like CURRENT_USER will not return user which changed tuple but the replication user). It would be nice if 0006 had regression test and 0007 TAP test. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services