On 30/08/13 01:32, Thomas Mueller wrote:
Hi,

> With reference to using ValueArray as key in non-unique situation, how are the required rows found, for example if the ValueArray [0] is the searched for value and [1] contains the row? I have tried to follow the MVSecondaryIndex code but the technique is not obvious (to me). It seems that a linear search is used with an iterator on the key set.

Well, if you are using the MVStore directly, I suggest not to use the ValueArray class (as it's a class internal to H2). Instead, I suggest to use an array (for example an object array), or your own key class.

But the idea is that the key of the map for the secondary index (for non-unique indexes) is the key value of the index, combined with the primary key. The value of the map is not used (you could store "boolean true" or something like that). So let's say the secondary index key is the name of the city ("New York", "Berlin") and duplicates are allowed, then the key of the map is ["New York", 1], ["New York", 2], ["Berlin", 3], where 1, 2, 3 is the primary key. Then searching for "New York", you create a key of the form ["New York", 0] (where 0 is the lowest possible primary key). And search for that, using MVMap.keyIterator(from), as in most cases you need to iterate over all entries for "New York". If you only need one result, you could use MVMap.higherKey(from).

For unique indexes it's simpler of course: just use the index key as the map key, and the primary key as the map value.

Regards,
Thomas


Excellent,

Thanks Thomas

Paul

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to