CQEngine query overhead / precompiled parameterized queries

200 views Asked by At

When I query an indexed collection many times and the query is the same and only differs in the attribute value, how big is the overhead to execute it?

Is there a way to precompile a parameterized query to get rid of this overhead?

Edit: Here's a simple benchmark showing that making multiple retrievals from a CQEngine collection with a hash index tends to be ~18 times slower than retrieving items from a LinkedHashMap.

https://github.com/Inego/cqe-simple-benchmark/blob/main/src/main/kotlin/Benchmark.kt

1

There are 1 answers

3
npgall On BEST ANSWER

There is no support for parameterized queries per-se.

However if you would like to reduce the overhead of constructing queries frequently, such as the impact on garbage collection, you can leverage the fact that queries are immutable and stateless, and cache frequently used queries.

Queries are trees. So you can also cache frequently used branches of queries and reassemble query trees on the fly where branches are retrieved from cache.

However that said, generally the overhead of constructing queries should be pretty small. Id recommend to benchmark your application to see if this really is worthwhile.