Quickest way to remove elements matching a query?

72 views
Skip to first unread message

Jonathan Baxter

unread,
Aug 29, 2018, 3:16:37 PM8/29/18
to cqengine-discuss
What is the quickest way to remove elements matching a Query? Currently I am planning to use the remove method on ResultSet.iterator but that seems suboptimal relative to the equivalent of a sql delete statement. The latter does not seem to be supported in cqengine, so I am wondering if there is some other "blessed" technique?

Iterator<T> it = indexedCollection.retrieve(query).iterator();
while (it.hasNext()) {
  it
.next();
  it
.remove();
}

vs:

indexedCollection.delete(query);

if such a thing existed.

Jonathan Baxter

unread,
Aug 30, 2018, 6:14:32 AM8/30/18
to cqengine-discuss
So using remove on the ResultSet Iterator doesn't work anyway (it's unmodifiable). What is the correct way to delete? I can collect all the objects matching a query and then do "removeAll" but I doubt that is efficient...

Niall

unread,
Dec 5, 2018, 6:22:06 PM12/5/18
to cqengine-discuss
There is no special trick per-se to remove objects matching a query.

For collections stored on-heap, the retrieval cost is low because only references are returned. And for collections stored off heap or on disk, each entire object needs to be retrieved anyway so its fields can be examined so it can be removed from all relevant indexes.

Your options are:
(1) fetch the objects matching a query and then call IndexedCollection.removeAll(objects)
(2) or to call remove(object) on-thefly for each one.
(3) or you can also do it in batches, where you fetch and then remove only a few at a time.

For IndexedCollections where you are using disk persistence, options 1 or 3 can have better performance, to minimise round trips to disk.

Reply all
Reply to author
Forward
0 new messages