fix(sql):优化删除语句中单主键条件的拼接逻辑

- 将单主键删除条件从 OR 拼接改为 IN 方式拼接
This commit is contained in:
axbest 2025-11-19 16:13:04 +08:00
parent 7185d2c79b
commit af3451b43f
2 changed files with 21 additions and 10 deletions

View File

@ -231,12 +231,14 @@ public class ClickhouseDialectImpl extends CommonsDialectImpl {
}
// 单主键
else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < ids.length; i++) {
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);
return sql.toString();
@ -294,12 +296,14 @@ public class ClickhouseDialectImpl extends CommonsDialectImpl {
}
// 单主键
else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) {
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));

View File

@ -47,6 +47,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
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.BLANK;
import static com.mybatisflex.core.constant.SqlConsts.BRACKET_LEFT;
@ -242,12 +243,14 @@ public class CommonsDialectImpl implements IDialect {
}
// 单主键
else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < ids.length; i++) {
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);
return sql.toString();
@ -776,12 +779,14 @@ public class CommonsDialectImpl implements IDialect {
}
// 单主键
else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) {
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));
@ -1025,12 +1030,14 @@ public class CommonsDialectImpl implements IDialect {
}
// 单主键
else {
sql.append(wrap(primaryKeys[0])).append(IN).append(BRACKET_LEFT);
for (int i = 0; i < primaryValues.length; i++) {
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)) {