From 2f5fb235b28a7c90fe8edbd26f56f50029030d8f Mon Sep 17 00:00:00 2001 From: Joe <1060287354@qq.com> Date: Sat, 4 Jul 2020 09:27:18 +0800 Subject: [PATCH] optimize isExistTable function (#3236) * Update EmbeddedStoragePersistServiceImpl.java If the table data volume is large, count (*) will be particularly slow * Update ExternalStoragePersistServiceImpl.java If the table data volume is large, count (*) will be particularly slow * Update ExternalStoragePersistServiceImpl.java * Update EmbeddedStoragePersistServiceImpl.java --- .../repository/embedded/EmbeddedStoragePersistServiceImpl.java | 2 +- .../repository/extrnal/ExternalStoragePersistServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java index 548fe61a5..2e62020da 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java @@ -2113,7 +2113,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService { } public boolean isExistTable(String tableName) { - String sql = "SELECT COUNT(*) FROM " + tableName; + String sql = String.format("select 1 from %s limit 1", tableName); try { databaseOperate.queryOne(sql, Integer.class); return true; diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java index a5ee6f166..bbdacd3e0 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java @@ -3147,7 +3147,7 @@ public class ExternalStoragePersistServiceImpl implements PersistService { } public boolean isExistTable(String tableName) { - String sql = "SELECT COUNT(*) FROM " + tableName; + String sql = String.format("select 1 from %s limit 1", tableName); try { jt.queryForObject(sql, Integer.class); return true;