ellecer / cqengine

Automatically exported from code.google.com/p/cqengine
0 stars 0 forks source link

Integrate UniqueIndex patch by Kinz Liu #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Following discussion in the forum: 
http://groups.google.com/group/cqengine-discuss

Patch attached.

Original issue reported on code.google.com by ni...@npgall.com on 4 Dec 2012 at 11:27

Attachments:

GoogleCodeExporter commented 9 years ago
Done, included in CQEngine 1.0.3.

I made some minor changes to the patch:

 - If an object is added to the IndexedCollection and it already exists in UniqueIndex, UniqueIndex will not throw an exception if the condition newObject.equals(existingObject) is true. This change brings UniqueIndex in line with the behaviour of other indexes (which safely can be notified multiple times about the same object), to avoid the need to add special logic for UniqueIndex in IndexedCollection

 - I added support for MultiValueAttribute. Attribute values become the keys in the index, so there is no problem per-se in an object having a multiple values for an attribute. The object will be added to the index multiple times, against one key for each of its attribute values. 

Multi-valued attributes can be used with unique index, as long as there is no 
overlap in values between objects. For example Car{features=radio,cd_player} 
and Car{features=sunroof,spare_tyre} can both be added to a UniqueIndex. But a 
third Car{features=alarm,sunroof} would cause an exception because there would 
already be an entry for sunroof. This is a contrived example, but some 
applications might have fields which contain multiple but naturally disjoint 
values, for example foreign key-type references, like 
Customer{List<CustomerOrder>}.

This will be a great addition so thanks again to Kinz Liu.

Original comment by ni...@npgall.com on 7 Dec 2012 at 10:46

GoogleCodeExporter commented 9 years ago
I updated the benchmark page: http://code.google.com/p/cqengine/wiki/Benchmark

UniqueIndex is *significantly* faster:
3600% faster than HashIndex at indexing unique attributes
30% faster than HashIndex in query performance

Actual figures are here: http://cqengine.googlecode.com/svn/wiki/documents/

Original comment by ni...@npgall.com on 8 Dec 2012 at 12:02

GoogleCodeExporter commented 9 years ago
I see the above patch missing in IndexedCollectionImpl.java in the latest 
release 1.2.1. Any reason this was not included in the release? 

Original comment by rubba...@gmail.com on 8 Oct 2013 at 9:31

GoogleCodeExporter commented 9 years ago
No features were removed AFAIK. UniqueIndex is still there (it's a core 
feature).

IndexedCollectionImpl no longer exists however. In version 1.1.0 it was renamed 
to ConcurrentIndexedCollection, because an additional implementation 
ObjectLockingIndexedCollection was also added.

What was in IndexedCollectionImpl.java is now in 
ConcurrentIndexedCollection.java, so see that class instead. Let me know if you 
don't find what you are looking for!

Original comment by ni...@npgall.com on 8 Oct 2013 at 9:59