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 1mMNWH-0000qK-7G for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Sep 2021 04:43:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mMNWG-0001yq-5b for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Sep 2021 04:43:08 +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 1mMNWF-0001yg-SB for pgsql-hackers@lists.postgresql.org; Sat, 04 Sep 2021 04:43:07 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mMNWD-0001nA-Fj for pgsql-hackers@postgresql.org; Sat, 04 Sep 2021 04:43:06 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id c206so2206505ybb.12 for ; Fri, 03 Sep 2021 21:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cdQYclF6FZkB77pYm8RvAOOiujjkqql6OKIRzo5myfI=; b=nlZD/1Qbgt6jomsgCDTCPQevWPqs4eGY+tMkM36bsq7gYlDOT4IML2z0EI6cPCH/iU PYHConDpIILPAcUVqdbX7mNXhMMThPMgx4vAyYHHuH1BJJfBwbwFedFyy2w63jWblZt6 SZR+FCJIGZX52qJk/Y74AzJKJ/+tropa35reYu3Z9JfjNhztF4CyhnPGe7O9g1dSmNXp p1RE020xvJvNqAw+Tgq1UHHOWk+8Lg1ieBA1Uw7+btGEXxgzWACHJLdSfUjMP1IdzKHe lQGdcI1hHON0yJHKmyu37eaWrQ07xrn95s6KGkaepnaWXGarXM9JdgrJIke9Ag3MgFs3 cr5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cdQYclF6FZkB77pYm8RvAOOiujjkqql6OKIRzo5myfI=; b=Ry0wgSdZF3OJZ9z7Wz3Ks6yu7gOgWzMPxlqdJPgTl3lspSkJdKxfKUyyhSfkBZKPel vGBQyJKzQROumZ1os7cXwCR3cdQh8WPXi9SoqSz95zc442u9rFuTky/GSq9C5tYlqul5 h5OBficE9mPqL3K6DXMuIPk8Le7cgs7ctXkuk9HN20gIpymf+Oxjuqr+zj5Eu4dkOq4c 77tP4iYpiiPgwJbhLPbSBppBidtkifYvNhKwmGg9lBQxXEKABCZ5Xbil2EJn5mdBz67p ADF+/trzdp3sng2vzSQ7Zys2UPN6SjXc+nQ/17wmKaEUy9OQZ4L59e97szpxTdkbYmMZ VC/g== X-Gm-Message-State: AOAM531dZ7KFHnQKCcl5ehGX7QckTFKw+l2L2DO6aw7eV7x55Ijys6K5 9ehP/TmO5a0JbpnEqcxiuOvYHCshH3PLRc8YAOZeN4UCfa5L2w== X-Google-Smtp-Source: ABdhPJyYmd56g8MNLyvvi37AEpZGH1iUlU+fNLYT1dSp4FfFkgzmf+vVJLWRDwuL5Z7ZylJe5Kszjw0truzBcOLJ2IU= X-Received: by 2002:a25:3244:: with SMTP id y65mr2990913yby.193.1630730584507; Fri, 03 Sep 2021 21:43:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Sat, 4 Sep 2021 10:12:53 +0530 Message-ID: Subject: Re: Column Filtering in Logical Replication To: Rahila Syed Cc: Tomas Vondra , Alvaro Herrera , Peter Smith , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Sep 2, 2021 at 2:51 AM Rahila Syed wrote: > >>> >>> Do we want to consider that the columns specified in the filter must >>> not have NOT NULL constraint? Because, otherwise, the subscriber will >>> error out inserting such rows? >>> >> I think you mean columns *not* specified in the filter must not have NOT NULL constraint >> on the subscriber, as this will break during insert, as it will try to insert NULL for columns >> not sent by the publisher. >> I will look into fixing this. Probably this won't be a problem in >> case the column is auto generated or contains a default value. >> > > I am not sure if this needs to be handled. Ideally, we need to prevent the subscriber tables from having a NOT NULL > constraint if the publisher uses column filters to publish the values of the table. There is no way > to do this at the time of creating a table on subscriber. > > As this involves querying the publisher for this information, it can be done at the time of initial table synchronization. > i.e error out if any of the subscribed tables has NOT NULL constraint on non-filter columns. > This will lead to the user dropping and recreating the subscription after removing the > NOT NULL constraint from the table. > I think the same can be achieved by doing nothing and letting the subscriber error out while inserting rows. > That makes sense and also it is quite possible that users don't have such columns in the tables on subscribers. I guess we can add such a recommendation in the docs instead of doing anything in the code. Few comments: ============ 1. + + /* + * Cannot specify column filter when REPLICA IDENTITY IS FULL + * or if column filter does not contain REPLICA IDENITY columns + */ + if (targetcols != NIL) + { + if (replidentfull) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cannot add relation \"%s\" to publication", + RelationGetRelationName(targetrel)), + errdetail("Cannot have column filter with REPLICA IDENTITY FULL"))); Why do we want to have such a restriction for REPLICA IDENTITY FULL? I think it is better to expand comments in that regards. 2. @@ -839,7 +839,6 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext, ereport(ERROR, (errcode(ERRCODE_BAD_COPY_FILE_FORMAT), errmsg("extra data after last expected column"))); - fieldno = 0; @@ -944,7 +992,6 @@ logicalrep_write_attrs(StringInfo out, Relation rel) flags |= LOGICALREP_IS_REPLICA_IDENTITY; pq_sendbyte(out, flags); - /* attribute name */ pq_sendstring(out, NameStr(att->attname)); @@ -953,6 +1000,7 @@ logicalrep_write_attrs(StringInfo out, Relation rel) /* attribute mode */ pq_sendint32(out, att->atttypmod); + } Spurious line removals and addition. -- With Regards, Amit Kapila.