sink: use where in operator in delete or update statement (#3788)#4470
Conversation
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@wk989898 This PR has conflicts, I have hold it. |
|
@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance of multi-row DELETE and UPDATE operations by adopting a more efficient SQL generation strategy. By defaulting to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
The pull request introduces a new DML batching mechanism for the MySQL sink, refactoring existing logic into mysql_writer_dml_batch.go to support three levels of batching: normal, per-event, and cross-event. A key enhancement is the introduction of a configurable where-clause strategy for multi-row UPDATE/DELETE statements, allowing for a more performant (col1,col2) IN ((?,?),(?,?)) format (v2) which falls back to the (... ) OR (... ) form (v1) when key columns contain NULL values. This new strategy is integrated into the sink configuration and tested. A review comment highlights a potential inaccuracy in the code's complexity analysis, noting that the generateBatchSQLInSafeMode might be more efficient than stated, while buildRowChangesForUnSafeBatch could have a higher complexity than implied.
| // Considering the batch algorithm in safe mode is O(n^3), which n is the number of rows. | ||
| // So we need to limit the number of rows in one batch to avoid performance issues. |
There was a problem hiding this comment.
The comment states that the safe mode batch algorithm is O(n^3). However, the implementation of generateBatchSQLInSafeMode uses a map to group rows, which appears to be more efficient than O(n^3). Conversely, the buildRowChangesForUnSafeBatch function for unsafe mode has a nested loop structure that could potentially approach O(n^3) complexity in worst-case scenarios. Please verify and update the comment for clarity, as it might be outdated or swapped.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/test all |
|
/test all |
|
@ti-chi-bot: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
This is an automated cherry-pick of #3788
What problem does this PR solve?
Issue Number: close #4121 ref #1645
What is changed and how it works?
Since pingcap/tiflow#8818 was introduced in v7.2.0, ticdc uses
where orinstead ofwhere inwhen there exist many rows. But actually, there is a performance regression because there is only an impact on the right side of the IN() predicate when there is one row constructor. For more details, see https://dev.mysql.com/doc/refman/5.7/en/range-optimization.html#row-constructor-range-optimization.This PR uses
where inas the default clause and decreases the downstream CPU usage.You can specify the whereClause param in sink-uri to back the previous where clause.
--sink-uri="mysql://root:123456@127.0.0.1:3306/?where-clause=v1"Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note
Summary by CodeRabbit
New Features
Behavior Changes
Tests