Optimize DatabaseManager.count(SelectQuery) to Avoid Full Entity Load
Currently, the default implementation of count(SelectQuery query) in DatabaseManager executes a full select() operation and then counts the results in memory.
⚠️ Current Behavior (Default Fallback)
default long count(SelectQuery query) {
Objects.requireNonNull(query, "query is required");
return this.select(DefaultSelectQuery.countBy(query)).count();
}
flowchart TD
subgraph Current Default Flow
A1[SelectQuery] --> B1[Run full select]
B1 --> C1[Return result stream]
C1 --> D1[Count items in stream]
end
subgraph Optimized Driver Flow
A2[SelectQuery] --> B2[Translate to native count query]
B2 --> C2[Execute at DB layer and return count]
end
✅ Tasks
-
[ ] Override
count(SelectQuery)in the following database drivers:- [ ] MongoDB (
jnosql-communication-document-mongodb) - [ ] Cassandra (
jnosql-communication-column-cassandra) - [ ] Couchbase (
jnosql-communication-document-couchbase) - [ ] HBase (
jnosql-communication-column-hbase) - [ ] ArangoDB (
jnosql-communication-document-arangodb) - [ ] Infinispan (
jnosql-communication-document-infinispan)
- [ ] MongoDB (
-
[ ] Add documentation to clarify performance and behavior expectations
@dearrudam I will move this one as well to you.
@otaviojava , JNoSQL Infinispan database driver provides a BucketManager only, which doesn't offer count capability, so, I think that we could disconsider it from this optimization request.
@otaviojava , I think that it's better to explore the JNoSQL HBase Database Driver implementation in another task because:
-
It provides a ColumnManager only and such one implementation doesn't support the count by columnFamily method by now.
-
Also, the count by SelectQuery is supporting a limited group of operators (
AND,OR,EQUALSandIN). It's using the HBase Get classes only by now. -
It looks like there are some HBase capabilities (combining
Filters (e.gSingleColumnValueFilter) or usingScanclasses in some points) that we could use to improve the JNoSQL Database Driver implementation.
What do you think?!
@dearrudam you are right, key-value does not support it as the same as Hbase.
Check the others, such as Tinkerpop and Neo4J.