Hi,
I document here my findings about pagination over relations. There are four 1-N relation types: LINKMAP, LINKSET, LINKLIST and LINKBAG. They seems to be stored as a list of rids right inside vertex/document (which is cool). LINKMAP, LINKSET, LINKLIST
are loaded all at once when you ask for corresponding document/vertex fields - this makes them unusable to store large number of entries. BTW in my testing I found that 10000 links to empty documents takes only 170KB. LINKBAG on the other side can be partially loaded and potentially contain infinite number of entries.
Unfortunately all these goodies completely useless when you want to display paginated list. MAP, SET and LIST cannot be used since you will have to load entire collection, sort it and only then display some small portion of it. LINKBAG does not maintain order so it is also useless. The only method which I can think of is to use “relational” way of doing things.
1. Add “foreign key” aka "one directional link" from child to parent. CREATE LINK parent FROM Child.parentId TO Parent.rid
2. Create SB-Tree index on “child” vertex/document which will store entries in correct order. Something like this: CREATE INDEX xyz ON Child (ParentId, SortKey) NOT UNIQUE
Since this is SB-Tree index hopefully index data will be sorted by “ParentId" and then “SortKey" which is exactly the order we need to display in a web page.
3. Select child entries from index which match your parent and ordering/sorting criteria. SELECT FROM INDEX:xyz WHERE ParentId = ? and SortKey > ? LIMIT PAGE_SIZE