From 4c9c191f62e082737d2524167bb48d0b2e847adf Mon Sep 17 00:00:00 2001 From: gongzhongqiang Date: Wed, 2 Aug 2023 13:58:15 +0800 Subject: [PATCH] Use limit to improve exists performance --- .../src/main/java/com/mybatisflex/core/service/IService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java index c59dc682..3504283e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java @@ -418,7 +418,7 @@ public interface IService { * @return {@code true} 数据存在,{@code false} 数据不存在。 */ default boolean exists(QueryWrapper query) { - return SqlUtil.toBool(count(query)); + return CollectionUtil.isNotEmpty(getMapper().selectListByQuery(query.limit(1))); } /** @@ -428,7 +428,7 @@ public interface IService { * @return {@code true} 数据存在,{@code false} 数据不存在。 */ default boolean exists(QueryCondition condition) { - return SqlUtil.toBool(count(condition)); + return CollectionUtil.isNotEmpty(getMapper().selectListByCondition(condition,1L)); } /**