Merge pull request #614 from AXBest/main

fix(sql):优化删除语句中单主键条件的拼接逻辑
This commit is contained in:
Michael Yang 2025-11-26 16:19:18 +08:00 committed by GitHub
commit 5814d254b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 10 deletions

View File

@ -231,12 +231,14 @@ public class ClickhouseDialectImpl extends CommonsDialectImpl {
} }
// 单主键 // 单主键
else { else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
if (i > 0) { if (i > 0) {
sql.append(OR); sql.append(DELIMITER);
} }
sql.append(wrap(primaryKeys[0])).append(EQUALS_PLACEHOLDER); sql.append(PLACEHOLDER);
} }
sql.append(BRACKET_RIGHT);
} }
prepareAuth(schema, table, sql, OperateType.DELETE); prepareAuth(schema, table, sql, OperateType.DELETE);
return sql.toString(); return sql.toString();
@ -294,12 +296,14 @@ public class ClickhouseDialectImpl extends CommonsDialectImpl {
} }
// 单主键 // 单主键
else { else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) { for (int i = 0; i < primaryValues.length; i++) {
if (i > 0) { if (i > 0) {
sql.append(OR); sql.append(DELIMITER);
} }
sql.append(wrap(primaryKeys[0])).append(EQUALS_PLACEHOLDER); sql.append(PLACEHOLDER);
} }
sql.append(BRACKET_RIGHT);
} }
sql.append(BRACKET_RIGHT).append(AND).append(buildLogicNormalCondition(logicDeleteColumn, tableInfo)); sql.append(BRACKET_RIGHT).append(AND).append(buildLogicNormalCondition(logicDeleteColumn, tableInfo));

View File

@ -47,6 +47,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static com.mybatisflex.core.constant.SqlConsts.AND; import static com.mybatisflex.core.constant.SqlConsts.AND;
import static com.mybatisflex.core.constant.SqlConsts.IN;
import static com.mybatisflex.core.constant.SqlConsts.ASTERISK; import static com.mybatisflex.core.constant.SqlConsts.ASTERISK;
import static com.mybatisflex.core.constant.SqlConsts.BLANK; import static com.mybatisflex.core.constant.SqlConsts.BLANK;
import static com.mybatisflex.core.constant.SqlConsts.BRACKET_LEFT; import static com.mybatisflex.core.constant.SqlConsts.BRACKET_LEFT;
@ -242,12 +243,14 @@ public class CommonsDialectImpl implements IDialect {
} }
// 单主键 // 单主键
else { else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
if (i > 0) { if (i > 0) {
sql.append(OR); sql.append(DELIMITER);
} }
sql.append(wrap(primaryKeys[0])).append(EQUALS_PLACEHOLDER); sql.append(PLACEHOLDER);
} }
sql.append(BRACKET_RIGHT);
} }
prepareAuth(schema, table, sql, OperateType.DELETE); prepareAuth(schema, table, sql, OperateType.DELETE);
return sql.toString(); return sql.toString();
@ -776,12 +779,14 @@ public class CommonsDialectImpl implements IDialect {
} }
// 单主键 // 单主键
else { else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) { for (int i = 0; i < primaryValues.length; i++) {
if (i > 0) { if (i > 0) {
sql.append(OR); sql.append(DELIMITER);
} }
sql.append(wrap(primaryKeys[0])).append(EQUALS_PLACEHOLDER); sql.append(PLACEHOLDER);
} }
sql.append(BRACKET_RIGHT);
} }
sql.append(BRACKET_RIGHT).append(AND).append(buildLogicNormalCondition(logicDeleteColumn, tableInfo)); sql.append(BRACKET_RIGHT).append(AND).append(buildLogicNormalCondition(logicDeleteColumn, tableInfo));
@ -1025,12 +1030,14 @@ public class CommonsDialectImpl implements IDialect {
} }
// 单主键 // 单主键
else { else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) { for (int i = 0; i < primaryValues.length; i++) {
if (i > 0) { if (i > 0) {
sql.append(OR); sql.append(DELIMITER);
} }
sql.append(wrap(primaryKeys[0])).append(EQUALS_PLACEHOLDER); sql.append(PLACEHOLDER);
} }
sql.append(BRACKET_RIGHT);
} }
if (StringUtil.hasText(logicDeleteColumn) || ArrayUtil.isNotEmpty(tenantIdArgs)) { if (StringUtil.hasText(logicDeleteColumn) || ArrayUtil.isNotEmpty(tenantIdArgs)) {