Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ebrBd-0005V5-Pq for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jan 2018 17:07:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ebrBc-0006Lw-PG for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jan 2018 17:07:40 +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.84_2) (envelope-from ) id 1ebrBc-0006Le-FS for pgsql-hackers@lists.postgresql.org; Wed, 17 Jan 2018 17:07:40 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ebrBZ-0002hC-Jf for pgsql-hackers@postgresql.org; Wed, 17 Jan 2018 17:07:39 +0000 Received: by mail-wm0-x22e.google.com with SMTP id b141so16743533wme.1 for ; Wed, 17 Jan 2018 09:07:36 -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:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=hI27Yr/g04tmrLuE2Xb84sv8JTDNF7awQAxmrPkYHtM=; b=gYxEqtE2gMfO0jiSPsrbJIZBnaXW0yEw+TgITeqlYVwGn+DH/z3TXD7+eimJ8wJA34 cnJbJMgXsCbl4eqnUTNUHgs9A6CWzJ94rXRy28fe1E4xbp/0wYm+8ilDaw1OfXZMp8Nc gCEjEOdUcjXhoEjqv3krO4M+H1N2XR0FoOB5xD1OCM+RGj7Fk+wb/jKNaGafTmXDnjaQ ayLKj1fK4jZzxlRrISzVJNEvdrkVONJP5suWxfXQG5x3ea46wVZzNIBIzQkIdhjhLzMx oPBzM3B9PXcB1S6VPH2NXF3seoBggtKi5c7ci7HtoOh8bflqAvk8INqC+AGWkcXaN4RF hCMg== 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:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=hI27Yr/g04tmrLuE2Xb84sv8JTDNF7awQAxmrPkYHtM=; b=IKEUClrzbLFhh4fyzQ6TN3KTQmSx22UTheSE3p99zzIDDVMV2VwKtQ4GPzBFZT0aE8 8wCscMguVFGQb0z/apTg6IO2mZPyl2gVq9UcG8N3wiUyu2SI2Rp5fxJALenlA91oM6hg JMfsZp97bZggzvCEW0w13DkcFc6QsLD3Kz50UjxzBYsB25O055Oxb70Vke0LjcQl/dX3 dzsggq5TK/oQZw7hadxsutLMzCEoAtO8YVnr0QS96kwLulYemhXmx018+l0jUtVBQ650 FEcK2+eIb219nD4tsfkE1NVpvB174CO4L2AzRCBICIWkU0ntOLPJdoGRLjXCX5LsFdqM 3q7Q== X-Gm-Message-State: AKwxytfXHo02enywEKPPmqbSjBpi6zigu790GWHAZEPICrgRC/ITIf6N MNSZanGspSr8CTfjzaNZPlEO8gRxyFRozJxuBOKEDcWTS9vF8vTTVcKN20mZYYg5YQDglhtSYkV +ujurbvX8QiuXr3KHF2JeE6Uv7QBI0mOplyNRxYorVrHRwyr9wRXdAR/NRz/zO8nOhK2jGHPpCu aZ/toDGRbEonM= X-Google-Smtp-Source: ACJfBovyuiQHBTb1Yecbv5Oil17zMjZVmvCgrpagxmGa3m3/GITACMJjp+DSN25fNR+9IZLvZm4gNQ== X-Received: by 10.80.144.169 with SMTP id c38mr4035302eda.210.1516208853627; Wed, 17 Jan 2018 09:07:33 -0800 (PST) Received: from [100.99.115.10] ([194.151.204.155]) by smtp.gmail.com with ESMTPSA id q3sm3439869edd.61.2018.01.17.09.07.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 09:07:32 -0800 (PST) Subject: Re: [PATCH] Logical decoding of TRUNCATE To: Marco Nenciarini , Simon Riggs Cc: PostgreSQL-development References: <269bf0d2-6ac4-c032-6979-22aad6a9f5fb@2ndquadrant.it> <20171229195536.cdzmgllfkln6wo6t@alap3.anarazel.de> <35a1d60b-f66d-4001-499b-2336ca81fc6c@2ndquadrant.it> <1a4ace10-1997-6644-d17a-5a17bf250270@2ndquadrant.it> <28a59551-b1f5-8ed4-65cf-76d17e7ee7e6@2ndquadrant.it> From: Petr Jelinek Message-ID: Date: Wed, 17 Jan 2018 18:07:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <28a59551-b1f5-8ed4-65cf-76d17e7ee7e6@2ndquadrant.it> 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 Hi, I reviewed 0001 in its own thread. So I think that we generally want this patch and I think the design decisions are right. Namely: TRUNCATE being treated as DELETE in terms of DML filtering makes sense to me as it is basically bulk delete, needs to be mentioned in release notes though. Adding special message to protocol is appropriate as truncate is more DML than DDL in sense of manipulating data so it should be replicated separately from other DDL Processing relations that were truncated when CASCADE is used separately is needed because we allow relations to be filtered by logical replication I see the patch adds new xlog record which is perhaps not ideal but the current one seems utterly unsuitable for decoding so I guess it's okay, especially when it's only added for wal_level = logical which it is. Also TRUNCATE is not exactly high tps operation. Things I am less convinced about: The patch will cascade truncation on downstream if cascade was specified on the upstream, that can potentially be dangerous and we either should not do it and only truncate the tables which were truncated upstream (but without restricting because of FKs), leaving the data inconsistent on downstream (like we do already with DELETE or UPDATE). Or maybe make it into either subscription or publication option so that user can chose the behaviour here as I am sure some people will want it to cascade (but the default should still IMHO be to not cascade as that's safer). > + /* logicalrep_rel_close call not needed, because ExecuteTruncateGuts > + * already closes the relations. Setting localrel to NULL in the map entry > + * is still needed. > + */ > + rel->localrel = NULL; This is somewhat ugly. Perhaps the ExecuteTruncateGuts should track which relations it opened and only close those and the rest should be closed by caller? That should also remove the other ugly part which is that the ExecuteTruncateGuts modifies the input list. What if caller wanted to use those relations it sent as parameter later? -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services