| title | summary |
|---|---|
Changefeed Log Filters |
Learn how to use the table filter and event filter of TiCDC. |
TiCDC supports filtering data by tables and events. This document introduces how to use the two types of filters.
Table filter is a feature that allows you to keep or filter out specific databases and tables by specifying the following configurations:
[filter]
# Filter rules
rules = ['*.*', '!test.*']Common filter rules:
rules = ['*.*']- Replicate all tables (not including system tables)
rules = ['test1.*']- Replicate all tables in the
test1database
- Replicate all tables in the
rules = ['*.*', '!scm1.tbl2']- Replicate all tables except for the
scm1.tbl2table
- Replicate all tables except for the
rules = ['scm1.tbl2', 'scm1.tbl3']- Only replicate tables
scm1.tbl2andscm1.tbl3
- Only replicate tables
rules = ['scm1.tidb_*']- Replicate all tables in the
scm1database whose names start withtidb_
- Replicate all tables in the
For more information, see Table filter syntax.
Starting in v6.2.0, TiCDC supports event filter. You can configure event filter rules to filter out the DML and DDL events that meet the specified conditions.
The following is an example of event filter rules:
[filter]
# The event filter rules must be under the `[filter]` configuration. You can configure multiple event filters at the same time.
[[filter.event-filters]]
matcher = ["test.worker"] # matcher is an allow list, which means this rule only applies to the worker table in the test database.
ignore-event = ["insert"] # Ignore insert events.
ignore-sql = ["^drop", "add column"] # Ignore DDLs that start with "drop" or contain "add column".
ignore-delete-value-expr = "name = 'john'" # Ignore delete DMLs that contain the condition "name = 'john'".
ignore-insert-value-expr = "id >= 100" # Ignore insert DMLs that contain the condition "id >= 100".
ignore-update-old-value-expr = "age < 18 or name = 'lili'" # Ignore update DMLs whose old value contains "age < 18" or "name = 'lili'".
ignore-update-new-value-expr = "gender = 'male' and age > 18" # Ignore update DMLs whose new value contains "gender = 'male'" and "age > 18".Description of configuration parameters:
-
matcher: the database and table that this event filter rule applies to. The syntax is the same as table filter.Note:
matchermatches the database name, so you need to pay extra attention when configuring it. For example, when theevent-filtersconfiguration is as follows:[filter] [[filter.event-filters]] matcher = ["test.t1"] ignore-sql = ["^drop"]
ignore-sql = ["^drop"]not only filters outDROP TABLE test.t1but also filters outDROP DATABASE test, becausematchercontains the database nametest.If you only want to filter out the specified table instead of the entire database, modify the
ignore-sqlvalue to["drop table"]. -
ignore-event: the event type to be ignored. This parameter accepts an array of strings. You can configure multiple event types. Currently, the following event types are supported:Event Type Alias Description all dml Matches all DML events all ddl Matches all DDL events insert DML Matches insertDML eventupdate DML Matches updateDML eventdelete DML Matches deleteDML eventcreate schema DDL create database Matches create databaseeventdrop schema DDL drop database Matches drop databaseeventcreate table DDL Matches create tableeventdrop table DDL Matches drop tableeventrename table DDL Matches rename tableeventtruncate table DDL Matches truncate tableeventalter table DDL Matches alter tableevent, including all clauses ofalter table,create indexanddrop indexadd table partition DDL Matches add table partitioneventdrop table partition DDL Matches drop table partitioneventtruncate table partition DDL Matches truncate table partitioneventcreate view DDL Matches create vieweventdrop view DDL Matches drop vieweventmodify schema charset and collate DDL Matches modify schema charset and collateeventrecover table DDL Matches recover tableeventrebase auto id DDL Matches rebase auto ideventmodify table comment DDL Matches modify table commenteventmodify table charset and collate DDL Matches modify table charset and collateeventexchange table partition DDL Matches exchange table partitioneventreorganize table partition DDL Matches reorganize table partitioneventalter table partitioning DDL Matches alter table partitioningeventremove table partitioning DDL Matches remove table partitioningeventadd column DDL Matches add columneventdrop column DDL Matches drop columneventmodify column DDL Matches modify columneventset default value DDL Matches set default valueeventadd primary key DDL Matches add primary keyeventdrop primary key DDL Matches drop primary keyeventrename index DDL Matches rename indexeventalter index visibility DDL Matches alter index visibilityeventalter ttl info DDL Matches alter ttl infoeventalter ttl remove DDL Matches DDL events that remove all TTL attributes of a table multi schema change DDL Matches DDL events that change multiple attributes of a table within the same DDL statement Note:
TiDB's DDL statements support changing multiple attributes of a single table at the same time, such as
ALTER TABLE t MODIFY COLUMN a INT, ADD COLUMN b INT, DROP COLUMN c;. This operation is defined as MultiSchemaChange. If you want to filter out this type of DDL, you need to configure"multi schema change"inignore-event. -
ignore-sql: the regular expressions of the DDL statements to be filtered out. This parameter accepts an array of strings, in which you can configure multiple regular expressions. This configuration only applies to DDL events. -
ignore-delete-value-expr: this parameter accepts a SQL expression that follows the default SQL mode, used to filter out theDELETEtype of DML events with a specified value. -
ignore-insert-value-expr: this parameter accepts a SQL expression that follows the default SQL mode, used to filter out theINSERTtype of DML events with a specified value. -
ignore-update-old-value-expr: this parameter accepts a SQL expression that follows the default SQL mode, used to filter out theUPDATEtype of DML events with a specified old value. -
ignore-update-new-value-expr: this parameter accepts a SQL expression that follows the default SQL mode, used to filter out theUPDATEDML events with a specified new value.
Note:
- When TiDB updates a value in the column of the clustered index, TiDB splits an
UPDATEevent into aDELETEevent and anINSERTevent. TiCDC does not identify such events as anUPDATEevent and thus cannot correctly filter out such events.- When you configure a SQL expression, make sure all tables that matches
matchercontain all the columns specified in the SQL expression. Otherwise, the replication task cannot be created. In addition, if the table schema changes during the replication, which results in a table no longer containing a required column, the replication task fails and cannot be resumed automatically. In such a situation, you must manually modify the configuration and resume the task.