Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
mymeiyi committed Nov 7, 2023
1 parent b224f64 commit c461ef0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
27 changes: 20 additions & 7 deletions docs/en/docs/data-operate/import/import-way/group-commit-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,23 @@ To reduce the CPU cost of SQL parsing and query planning, we provide the `Prepar
url = jdbc:mysql://127.0.0.1:9030/db?useServerPrepStmts=true
```

2. Using `PreparedStatement`
2. Enable `enable_insert_group_commit` session variable, there are two ways to do it:

* Add `sessionVariables=enable_insert_group_commit=true` in JDBC url

```
url = jdbc:mysql://127.0.0.1:9030/db?useServerPrepStmts=true&sessionVariables=enable_insert_group_commit=true
```

*Use `SET enable_insert_group_commit = true;` command

```
try (Statement statement = conn.createStatement()) {
statement.execute("SET enable_insert_group_commit = true;");
}
```

3. Using `PreparedStatement`

```java
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
Expand Down Expand Up @@ -210,13 +226,10 @@ private static void groupCommitInsert() throws Exception {

private static void groupCommitInsertBatch() throws Exception {
Class.forName(JDBC_DRIVER);
// rewriteBatchedStatements=true and cachePrepStmts=true
// add rewriteBatchedStatements=true and cachePrepStmts=true in JDBC url
// enable session variables by sessionVariables=enable_insert_group_commit=true in JDBC url
try (Connection conn = DriverManager.getConnection(
String.format(URL_PATTERN + "&rewriteBatchedStatements=true&cachePrepStmts=true", HOST, PORT, DB), USER, PASSWD)) {
// enable session variable 'enable_insert_group_commit'
try (Statement statement = conn.createStatement()) {
statement.execute("SET enable_insert_group_commit = true;");
}
String.format(URL_PATTERN + "&rewriteBatchedStatements=true&cachePrepStmts=true&sessionVariables=enable_insert_group_commit=true", HOST, PORT, DB), USER, PASSWD)) {

String query = "insert into " + TBL + " values(?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,23 @@ curl --location-trusted -u {user}:{passwd} -T data.csv -H "group_commit:true" -
url = jdbc:mysql://127.0.0.1:9030/db?useServerPrepStmts=true
```

2. 使用 `PreparedStatement`
2. 开启 `enable_insert_group_commit` session变量,有如下两种方式:

* 通过JDBC url设置,增加`sessionVariables=enable_insert_group_commit=true`

```
url = jdbc:mysql://127.0.0.1:9030/db?useServerPrepStmts=true&sessionVariables=enable_insert_group_commit=true
```

* 通过执行SQL设置

```
try (Statement statement = conn.createStatement()) {
statement.execute("SET enable_insert_group_commit = true;");
}
```

3. 使用 `PreparedStatement`

```java
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
Expand Down Expand Up @@ -211,13 +227,10 @@ private static void groupCommitInsert() throws Exception {

private static void groupCommitInsertBatch() throws Exception {
Class.forName(JDBC_DRIVER);
// rewriteBatchedStatements=true and cachePrepStmts=true
// add rewriteBatchedStatements=true and cachePrepStmts=true in JDBC url
// enable session variables by sessionVariables=enable_insert_group_commit=true in JDBC url
try (Connection conn = DriverManager.getConnection(
String.format(URL_PATTERN + "&rewriteBatchedStatements=true&cachePrepStmts=true", HOST, PORT, DB), USER, PASSWD)) {
// enable session variable 'enable_insert_group_commit'
try (Statement statement = conn.createStatement()) {
statement.execute("SET enable_insert_group_commit = true;");
}
String.format(URL_PATTERN + "&rewriteBatchedStatements=true&cachePrepStmts=true&sessionVariables=enable_insert_group_commit=true", HOST, PORT, DB), USER, PASSWD)) {

String query = "insert into " + TBL + " values(?, ?, ?)";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
Expand Down Expand Up @@ -258,7 +271,7 @@ private static void groupCommitInsertBatch() throws Exception {

+ group_commit_interval_ms

攒批写入开启多久后结束,默认为10000,即10秒。
攒批写入开启多久后结束,单位为毫秒,默认为10000,即10秒。

+ group_commit_replay_wal_dir

Expand Down

0 comments on commit c461ef0

Please sign in to comment.