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



On Thu, Aug 29, 2013 at 5:19 PM, Paul F Fraser <[email protected]> wrote:

>  On 30/08/13 00:41, Thomas Mueller wrote:
>
> Hi,
>
>  > Is it practical with MVStore to use a single key with a list as the
> value containing the row id's for a simple single column  index?
>
>  Yes, unless the list of values doesn't fit in memory. Well, if the list
> of values is very big (multiple KB) *and* changes a lot (many writes
> operations) then you probably shouldn't do that for performance reasons,
> but it's possible.
>
>  But you could also use separate keys. If the key is large (many bytes)
> and the value is small, then you should enable compression unless file size
> isn't an issue.
>
>  Regards,
> Thomas
>
>  I might have done mapDB a disservice. It was failing with "Write thread
> failed" after a few hundred lines, but i have just retried it and it worked
> OK.
> Not sure why, but I need to investigate.
>
> 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.
>
> regards
>
> 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.
>

-- 
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