RE: row filtering for logical replication

Поиск
Список
Период
Сортировка
От houzj.fnst@fujitsu.com
Тема RE: row filtering for logical replication
Дата
Msg-id OS0PR01MB571625D4A5CC1DAB4045B2BB94919@OS0PR01MB5716.jpnprd01.prod.outlook.com
обсуждение исходный текст
Ответ на Re: row filtering for logical replication  (Peter Smith <smithpb2250@gmail.com>)
Ответы Re: row filtering for logical replication  (Peter Smith <smithpb2250@gmail.com>)
Re: row filtering for logical replication  (Peter Smith <smithpb2250@gmail.com>)
Список pgsql-hackers
On Fri, Nov 5, 2021 1:14 PM Peter Smith <smithpb2250@gmail.com> wrote:
> PSA new set of v37* patches.

Thanks for updating the patches.
Few comments:

1) v37-0001

I think it might be better to also show the filter expression in '\d+
tablename' command after publication description.

2) v37-0004

+    /* Scan the expression tree for referenceable objects */
+    find_expr_references_walker(expr, &context);
+
+    /* Remove any duplicates */
+    eliminate_duplicate_dependencies(context.addrs);
+

The 0004 patch currently use find_expr_references_walker to get all the
reference objects. I am thinking do we only need get the columns in the
expression ? I think maybe we can check the replica indentity like[1].

3) v37-0005

- no parse nodes of any kind other than Var, OpExpr, Const, BoolExpr, FuncExpr

I think there could be other node type which can also be considered as simple
expression, for exmaple T_NullIfExpr.

Personally, I think it's natural to only check the IMMUTABLE and
whether-user-defined in the new function rowfilter_walker. We can keep the
other row-filter errors which were thrown for EXPR_KIND_PUBLICATION_WHERE in
the 0001 patch.

[1]
rowfilter_expr_checker
...
            if (replica_identity == REPLICA_IDENTITY_DEFAULT)
                context.bms_replident = RelationGetIndexAttrBitmap(rel, INDEX_ATTR_BITMAP_PRIMARY_KEY);
            else
                context.bms_replident = RelationGetIndexAttrBitmap(rel, INDEX_ATTR_BITMAP_IDENTITY_KEY);

            (void) rowfilter_expr_replident_walker(rfnode, &context);

...
static bool
rowfilter_expr_replident_walker(Node *node, rf_context *context)
{
    if (node == NULL)
        return false;

    if (IsA(node, Var))
    {
        Oid            relid = RelationGetRelid(context->rel);
        Var           *var = (Var *) node;
        AttrNumber     attnum = var->varattno - FirstLowInvalidHeapAttributeNumber;

        if (!bms_is_member(attnum, context->bms_replident))
        {
            const char *colname = get_attname(relid, attnum, false);
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
                    errmsg("cannot add relation \"%s\" to publication",
                            RelationGetRelationName(context->rel)),
                    errdetail("Row filter column \"%s\" is not part of the REPLICA IDENTITY",
                                colname)));

            return false;
        }

        return true;
    }

    return expression_tree_walker(node, rowfilter_expr_replident_walker,
                                  (void *) context);
}

Best regards,
Hou zj


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ken Kato
Дата:
Сообщение: [PATCH] pg_stat_statements Configuration Parameters Documentation
Следующее
От: Greg Nancarrow
Дата:
Сообщение: Re: Skipping logical replication transactions on subscriber side