@@ -705,8 +705,8 @@ public static void deleteKeyValue_Transaction(Start start, Connection con, Tenan
705705 public static long getUsersCount (Start start , AppIdentifier appIdentifier , RECIPE_ID [] includeRecipeIds )
706706 throws SQLException , StorageQueryException {
707707 StringBuilder QUERY = new StringBuilder (
708- "SELECT COUNT(DISTINCT primary_or_recipe_user_id ) AS total FROM " +
709- getConfig (start ).getUsersTable ());
708+ "SELECT COUNT(* ) AS total FROM (" );
709+ QUERY . append ( "SELECT primary_or_recipe_user_id FROM " + getConfig (start ).getUsersTable ());
710710 QUERY .append (" WHERE app_id = ?" );
711711 if (includeRecipeIds != null && includeRecipeIds .length > 0 ) {
712712 QUERY .append (" AND recipe_id IN (" );
@@ -719,6 +719,7 @@ public static long getUsersCount(Start start, AppIdentifier appIdentifier, RECIP
719719 }
720720 QUERY .append (")" );
721721 }
722+ QUERY .append (" GROUP BY primary_or_recipe_user_id) AS uniq_users" );
722723
723724 return execute (start , QUERY .toString (), pst -> {
724725 pst .setString (1 , appIdentifier .getAppId ());
@@ -739,7 +740,8 @@ public static long getUsersCount(Start start, AppIdentifier appIdentifier, RECIP
739740 public static long getUsersCount (Start start , TenantIdentifier tenantIdentifier , RECIPE_ID [] includeRecipeIds )
740741 throws SQLException , StorageQueryException {
741742 StringBuilder QUERY = new StringBuilder (
742- "SELECT COUNT(DISTINCT primary_or_recipe_user_id) AS total FROM " + getConfig (start ).getUsersTable ());
743+ "SELECT COUNT(*) AS total FROM (" );
744+ QUERY .append ("SELECT primary_or_recipe_user_id FROM " + getConfig (start ).getUsersTable ());
743745 QUERY .append (" WHERE app_id = ? AND tenant_id = ?" );
744746 if (includeRecipeIds != null && includeRecipeIds .length > 0 ) {
745747 QUERY .append (" AND recipe_id IN (" );
@@ -753,6 +755,8 @@ public static long getUsersCount(Start start, TenantIdentifier tenantIdentifier,
753755 QUERY .append (")" );
754756 }
755757
758+ QUERY .append (" GROUP BY primary_or_recipe_user_id) AS uniq_users" );
759+
756760 return execute (start , QUERY .toString (), pst -> {
757761 pst .setString (1 , tenantIdentifier .getAppId ());
758762 pst .setString (2 , tenantIdentifier .getTenantId ());
0 commit comments