Skip to content

Commit

Permalink
Use join instead of subquery as join seems slightly faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdonohue committed Oct 31, 2023
1 parent 9832259 commit 9c0bf08
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public int countRows(Context context) throws SQLException {
@Override
public List<Group> findByParent(Context context, Group parent, int pageSize, int offset) throws SQLException {
Query query = createQuery(context,
"from Group where (from Group g where g.id = :parent_id) in elements (parentGroups)");
"SELECT g FROM Group g JOIN g.parentGroups pg " +
"WHERE pg.id = :parent_id");
query.setParameter("parent_id", parent.getID());
if (pageSize > 0) {
query.setMaxResults(pageSize);
Expand All @@ -213,8 +214,8 @@ public List<Group> findByParent(Context context, Group parent, int pageSize, int
}

public int countByParent(Context context, Group parent) throws SQLException {
Query query = createQuery(context, "SELECT count(*) from Group " +
"where (from Group g where g.id = :parent_id) in elements (parentGroups)");
Query query = createQuery(context, "SELECT count(g) FROM Group g JOIN g.parentGroups pg " +
"WHERE pg.id = :parent_id");
query.setParameter("parent_id", parent.getID());

return count(query);
Expand Down

0 comments on commit 9c0bf08

Please sign in to comment.