This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new be53e51a25 [Docs][Connector-V2] Explain MySQL batch statement cache 
sizing (#13604)
be53e51a25 is described below

commit be53e51a2504fa9779b442cd27c7d9f23b1caf01
Author: Daniel <[email protected]>
AuthorDate: Mon Nov 30 14:17:33 2026 +0000

    [Docs][Connector-V2] Explain MySQL batch statement cache sizing (#13604)
---
 docs/en/connectors/sink/Jdbc.md | 19 +++++++++++++++++++
 docs/zh/connectors/sink/Jdbc.md | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/docs/en/connectors/sink/Jdbc.md b/docs/en/connectors/sink/Jdbc.md
index f50457f593..05b378a942 100644
--- a/docs/en/connectors/sink/Jdbc.md
+++ b/docs/en/connectors/sink/Jdbc.md
@@ -710,8 +710,27 @@ When `is_exactly_once = true`, JDBC Sink uses XA 
transactions. Before enabling i
 - MySQL requires a server and Connector/J combination that supports the XA 
operations used by the sink. Accounts that perform XA recovery may also require 
the `XA_RECOVER_ADMIN` privilege; check the requirements for your MySQL version.
 - Do not configure `sink.flush.interval`; XA transaction boundaries are 
controlled by checkpoints.
 
+## MySQL batch write tuning
+
 For MySQL non-XA batch jobs, adding `rewriteBatchedStatements=true` to the 
JDBC URL can improve throughput. Validate the effect with your driver version 
and workload.
 
+With MySQL Connector/J, also compare client-side preparation with server-side 
preparation and statement caching. Add the options to the existing URL, 
retaining other required connection parameters. For example, the following 
fragment belongs inside an existing JDBC sink configuration:
+
+```hocon
+url = 
"jdbc:mysql://mysql-host:3306/example?rewriteBatchedStatements=true&useServerPrepStmts=true&cachePrepStmts=true&prepStmtCacheSize=4&prepStmtCacheSqlLimit=65536"
+batch_size = 1000
+```
+
+These are measurement starting points, not SeaTunnel defaults or a guarantee 
that server-side preparation is faster. Keep the sink's required driver, 
credentials, database and table settings.
+
+- `useServerPrepStmts` requests server-side preparation when supported; 
`cachePrepStmts` enables statement caching.
+- `prepStmtCacheSize` bounds cached entries per physical connection. The small 
example cache suits a fixed SQL workload; size it for the actual tables and SQL 
shapes, accounting for connection and writer concurrency.
+- `prepStmtCacheSqlLimit` limits the SQL length eligible for caching. 
Connector/J 8.0.33 defaults to 256. A rewritten multi-row INSERT can exceed 
that limit, so enabling caching alone may not reuse it. Choose the limit using 
the generated SQL length, rather than the row payload size.
+
+Measure rows per second, memory and server prepared-statement usage with 
representative row widths and batch sizes. Check packet limits and the server's 
`max_prepared_stmt_count` before increasing batch or cache sizes. When the 
source also uses MySQL, measure source and sink URL changes independently; an 
end-to-end result does not isolate either side. This example does not select a 
transaction policy or apply to XA tuning.
+
+See the Connector/J [performance 
properties](https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-performance-extensions.html)
 and [prepared-statement 
properties](https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-prepared-statements.html).
+
 ## Driver reference
 
 The following values are starting points. Confirm the driver artifact and 
version against the database vendor's compatibility matrix.
diff --git a/docs/zh/connectors/sink/Jdbc.md b/docs/zh/connectors/sink/Jdbc.md
index 598dd494d2..f3e2c4575a 100644
--- a/docs/zh/connectors/sink/Jdbc.md
+++ b/docs/zh/connectors/sink/Jdbc.md
@@ -705,8 +705,27 @@ batch_size = 1000
 - MySQL Server 和 Connector/J 的组合必须支持 Sink 使用的 XA 操作。执行 XA recovery 的账号还可能需要 
`XA_RECOVER_ADMIN` 权限,请按所用 MySQL 版本的要求配置。
 - 不要配置 `sink.flush.interval`,XA 事务边界由 checkpoint 控制。
 
+## MySQL 批量写入调优
+
 对于非 XA 的 MySQL 批量任务,可以尝试在 JDBC URL 中加入 `rewriteBatchedStatements=true` 
提升吞吐;实际效果应结合驱动版本和业务负载验证。
 
+使用 MySQL Connector/J 时,还应对比客户端预编译与服务端预编译、语句缓存的组合。将参数合并到现有 
URL,保留其他必要的连接参数。以下片段放入已有的 JDBC Sink 配置中:
+
+```hocon
+url = 
"jdbc:mysql://mysql-host:3306/example?rewriteBatchedStatements=true&useServerPrepStmts=true&cachePrepStmts=true&prepStmtCacheSize=4&prepStmtCacheSqlLimit=65536"
+batch_size = 1000
+```
+
+这些值用于开始测量,不是 SeaTunnel 默认值,也不保证服务端预编译一定更快。仍需保留 Sink 必填的驱动、账号、密码、数据库和表配置。
+
+- `useServerPrepStmts` 在受支持时请求服务端预编译;`cachePrepStmts` 开启语句缓存。
+- `prepStmtCacheSize` 限制每个物理连接的缓存条目数。示例的小缓存适合固定 SQL 负载;实际应按表数量和 SQL 
形态设置,并考虑连接数和写入并发。
+- `prepStmtCacheSqlLimit` 限制可缓存的 SQL 长度。Connector/J 8.0.33 的默认值为 256。改写后的多行 
INSERT 可能超过该限制,因此仅开启缓存未必能复用语句。应按生成 SQL 的长度选择上限,而不是按行数据大小选择。
+
+使用有代表性的行宽和批大小,测量吞吐、内存及服务端预编译语句占用。增大批大小或缓存前,检查包大小限制和服务端的 
`max_prepared_stmt_count`。源端也是 MySQL 时,应分别测量 Source 与 Sink 的 URL 
调整效果;端到端结果不能单独归因于某一端。该示例不选择事务策略,也不用于 XA 调优。
+
+参阅 Connector/J 
的[性能参数](https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-performance-extensions.html)和[预编译语句参数](https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-prepared-statements.html)。
+
 ## 驱动参考
 
 下表仅作为起点;驱动制品和版本应以数据库厂商的兼容矩阵为准。

Reply via email to