Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Add JoinTable #16

Open
aaronc opened this issue Feb 11, 2020 · 1 comment
Open

Add JoinTable #16

aaronc opened this issue Feb 11, 2020 · 1 comment

Comments

@aaronc
Copy link
Member

aaronc commented Feb 11, 2020

In https://github.com/regen-network/cosmos-modules/pull/14/files#diff-cd553207888c76d3acb6e9284c4e02e4, group member table and vote table are effectively "join tables" and their primary key is derived from two fields rather than one. Having them as natural key tables is a bit inefficient because then two indexes are needed, when this could be reduced to one with the table itself serving as an index in one direction. For example, the group member primary key is just concat(group, member) so this is sufficient for prefix scans already (assuming we add a final length byte).

So what about a JoinTable that instead of NaturalKeyed takes an interface like:

type JoinKeyed interface {
  JoinKeys() [][]byte
}

Then the interface for JoinTable could be something like:

type JoinTable interface {
  Table
  HasRelation(joinKeys [][]byte) bool
  GetOneByRelation(joinKeys [][]byte, dest interface{}) error
}

Thoughts @alpe?

@alpe
Copy link
Collaborator

alpe commented Feb 12, 2020

🙈 I missed this ticket but noticed the same "problem" in the code with the redundant index. My approach to this would be #17 .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants