Skip to content

Commit

Permalink
Fix bug: count sql statement leak (#1640)
Browse files Browse the repository at this point in the history
fix resultset leak for count query
fixed #1626
  • Loading branch information
z7658329 authored Nov 10, 2021
1 parent d9b70d7 commit 299449b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public default boolean olap() {
return false;
}

public interface BackendIterator<T> extends Iterator<T> {
public interface BackendIterator<T> extends Iterator<T>, AutoCloseable {

public void close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public Number queryNumber(Session session, Query query) {
return IteratorUtils.of(rs.resultSet().getLong(1));
} catch (SQLException e) {
throw new BackendException(e);
} finally {
rs.close();
}
});
return aggregate.reduce(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ public Number queryNumber(Session session, Query query) {

assert aggregate.func() == AggregateFunc.COUNT;
assert query.noLimit();
Iterator<BackendColumn> results = this.queryBy(session, query);
if (results instanceof Countable) {
return ((Countable) results).count();
try (BackendColumnIterator results = this.queryBy(session, query)) {
if (results instanceof Countable) {
return ((Countable) results).count();
}
return IteratorUtils.count(results);
}
return IteratorUtils.count(results);
}

@Override
Expand Down

0 comments on commit 299449b

Please sign in to comment.