Hello!

I'm using MVStore to implement a persistent data store for an
application. I'm using MVStore directly because there's a requirement
that multiple processes can access the data store concurrently without
there being a mediating server process running. Thankfully there'll
only be one writer and a small number of readers.

I'm slightly confused as to how to represent a particular data
structure efficiently. It's pretty simple, so I'll describe it in terms
of SQL:

  create table t (
    group integer not null,
    member integer not null,
    primary key (group, member)
  );

I think the natural way this would be expressed as a plain Java data
structure would be:

  Map<Integer, Set<Integer>>

I want to execute queries such as:

  select t.member from t where group = ?;

I'm not sure what the preferred way to declare the above is in terms of
the MVStore maps. The documentation says:

  "In database terms, a map can be used like a table, where the key of
  the map is the primary key of the table, and the value is the row."

But in this case, the primary key and the row are equivalent. This
would suggest that I'd have to write code that does something like:

  MVMap<...> map;
  Integer group;

  for (var entry : map.entrySet()) {
    if (entry.getKey().group().equals(group)) {
      // Collect member here
    }
  }

Which seems like it would be O(N) over the entire database just to
collect a subset of the "rows".

What's the expected/preferred way to do this so that I can efficiently
access members per-group?

--
Mark Raynsford | https://www.io7m.com

-- 
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 h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/20221029094638.61cd60e9%40sunflower.int.arc7.info.

Reply via email to