Skip to content

Commit

Permalink
bugfix: forbidden use order by or limit in multi sql (apache#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
caohdgege committed Dec 24, 2020
1 parent ab01b84 commit 08fbcef
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:

runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
matrix:
java: [8, 11]
os: [ ubuntu-18.04 ]
Expand Down
12 changes: 12 additions & 0 deletions changes/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
### feature:

- [[#3172](https://github.com/seata/seata/pull/3172)] 支持undolog压缩
- [[#3372](https://github.com/seata/seata/pull/3372)] saga模式下支撑用户自定义是否更新最后一次重试日志


### bugfix:

- [[#3258](https://github.com/seata/seata/pull/3258)] 修复AsyncWorker潜在的OOM问题
- [[#3293](https://github.com/seata/seata/pull/3293)] 修复配置缓存获取值时类型不匹配的bug
- [[#3241](https://github.com/seata/seata/pull/3241)] 禁止在多SQL的情况下使用 limit 和 order by 语法



### optimize:
Expand All @@ -39,6 +42,13 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#3365](https://github.com/seata/seata/pull/3365)] 修复ParameterParserTest测试用例
- [[#3359](https://github.com/seata/seata/pull/3359)] 删除未使用的测试用例
- [[#3397](https://github.com/seata/seata/pull/3397)] 添加更改记录文件夹



### test

- [[#3381](https://github.com/seata/seata/pull/3381)] 添加 TmClient 的测试用例


非常感谢以下 contributors 的代码贡献。若有无意遗漏,请报告。

Expand All @@ -49,6 +59,8 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [jsbxyyx](https://github.com/jsbxyyx)
- [caohdgege](https://github.com/caohdgege)
- [a364176773](https://github.com/a364176773)
- [anselleeyy](https://github.com/anselleeyy)
- [Ifdevil](https://github.com/Ifdevil)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

Expand Down
10 changes: 9 additions & 1 deletion changes/en-us/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
### feature:

- [[#3172](https://github.com/seata/seata/pull/3172)] support rollback info compress
- [[#3372](https://github.com/seata/seata/pull/3372)] Saga support customize whether update last retry log


### bugfix:

- [[#3258](https://github.com/seata/seata/pull/3258)] fix AsyncWorker potential OOM problem
- [[#3293](https://github.com/seata/seata/pull/3293)] configuration cache get value cast exception
- [[#3241](https://github.com/seata/seata/pull/3241)] forbidden use order by or limit in multi sql


### optimize:
Expand All @@ -39,6 +41,10 @@
- [[#3365](https://github.com/seata/seata/pull/3365)] optimize ParameterParserTest test case failed
- [[#3359](https://github.com/seata/seata/pull/3359)] remove unused test case
- [[#3397](https://github.com/seata/seata/pull/3397)] add the change records folder

### test

- [[#3381](https://github.com/seata/seata/pull/3381)] test case for tmClient

Thanks to these contributors for their code commits. Please report an unintended omission.

Expand All @@ -48,7 +54,9 @@
- [hoverruan](https://github.com/hoverruan )
- [jsbxyyx](https://github.com/jsbxyyx)
- [caohdgege](https://github.com/caohdgege)
- [a364176773](https://github.com/a364176773)
- [a364176773](https://github.com/a364176773)
- [anselleeyy](https://github.com/anselleeyy)
- [Ifdevil](https://github.com/Ifdevil)

Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/
package io.seata.rm.datasource.exec;

import io.seata.common.exception.NotSupportYetException;
import io.seata.common.util.StringUtils;


import io.seata.rm.datasource.ColumnUtils;
import io.seata.rm.datasource.StatementProxy;
import io.seata.rm.datasource.sql.struct.TableMeta;
import io.seata.rm.datasource.sql.struct.TableRecords;
import io.seata.sqlparser.ParametersHolder;
import io.seata.sqlparser.SQLDeleteRecognizer;
import io.seata.sqlparser.SQLRecognizer;

Expand Down Expand Up @@ -55,6 +57,15 @@ protected TableRecords beforeImage() throws SQLException {
for (SQLRecognizer recognizer : sqlRecognizers) {
sqlRecognizer = recognizer;
SQLDeleteRecognizer visitor = (SQLDeleteRecognizer) recognizer;

ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder)statementProxy : null;
if (StringUtils.isNotBlank(visitor.getLimit(parametersHolder, paramAppenderList))) {
throw new NotSupportYetException("Multi delete SQL with limit condition is not support yet !");
}
if (StringUtils.isNotBlank(visitor.getOrderBy())) {
throw new NotSupportYetException("Multi delete SQL with orderBy condition is not support yet !");
}

String whereConditionStr = buildWhereCondition(visitor, paramAppenderList);
if (StringUtils.isBlank(whereConditionStr)) {
whereCondition = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.StringJoiner;

import io.seata.common.exception.NotSupportYetException;
import io.seata.common.util.IOUtil;
import io.seata.common.util.StringUtils;
import io.seata.config.Configuration;
Expand All @@ -36,6 +37,7 @@
import io.seata.rm.datasource.StatementProxy;
import io.seata.rm.datasource.sql.struct.TableMeta;
import io.seata.rm.datasource.sql.struct.TableRecords;
import io.seata.sqlparser.ParametersHolder;
import io.seata.sqlparser.SQLRecognizer;
import io.seata.sqlparser.SQLUpdateRecognizer;

Expand Down Expand Up @@ -79,6 +81,15 @@ protected TableRecords beforeImage() throws SQLException {
for (SQLRecognizer recognizer : sqlRecognizers) {
sqlRecognizer = recognizer;
SQLUpdateRecognizer sqlUpdateRecognizer = (SQLUpdateRecognizer) recognizer;

ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder)statementProxy : null;
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getLimit(parametersHolder, paramAppenderList))) {
throw new NotSupportYetException("Multi update SQL with limit condition is not support yet !");
}
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getOrderBy())) {
throw new NotSupportYetException("Multi update SQL with orderBy condition is not support yet !");
}

List<String> updateColumns = sqlUpdateRecognizer.getUpdateColumns();
updateColumnsSet.addAll(updateColumns);
if (noWhereCondition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.util.JdbcConstants;
import com.google.common.collect.Lists;
import io.seata.common.exception.NotSupportYetException;
import io.seata.rm.datasource.ConnectionProxy;
import io.seata.rm.datasource.DataSourceProxy;
import io.seata.rm.datasource.StatementProxy;
Expand Down Expand Up @@ -174,9 +175,38 @@ public void testBeforeImageAndAfterImages() throws SQLException {
Assertions.assertTrue(itemSet.contains("table_update_executor_test2"));
Assertions.assertEquals(items.size(), 2);

// contains limit delete
sql = "delete from table_update_executor_test2 where id = 2;delete from table_update_executor_test2 where id = 2 limit 1;";
multi = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL);
executor = new MultiExecutor(statementProxy, (statement, args) -> {
return null;
}, multi);
Assertions.assertThrows(NotSupportYetException.class, executor::beforeImage);

// contains order by and limit delete
sql = "delete from table_update_executor_test2 where id = 2;delete from table_update_executor_test2 where id = 2 order by id desc limit 1;";
multi = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL);
executor = new MultiExecutor(statementProxy, (statement, args) -> {
return null;
}, multi);
Assertions.assertThrows(NotSupportYetException.class, executor::beforeImage);


//contains order by update
sql = "update table_update_executor_test set name = 'WILL' where id = 1;update table_update_executor_test set name = 'WILL' where id = 1 order by id desc;";
multi = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL);
executor = new MultiExecutor(statementProxy, (statement, args) -> {
return null;
}, multi);
Assertions.assertThrows(NotSupportYetException.class, executor::beforeImage);

//contains order by and limit update
sql = "update table_update_executor_test set name = 'WILL' where id = 1;update table_update_executor_test set name = 'WILL' where id = 1 order by id desc limit 1;";
multi = SQLVisitorFactory.get(sql, JdbcConstants.MYSQL);
executor = new MultiExecutor(statementProxy, (statement, args) -> {
return null;
}, multi);
Assertions.assertThrows(NotSupportYetException.class, executor::beforeImage);
}
}

0 comments on commit 08fbcef

Please sign in to comment.