Rid Bag threshold and strategy for fetching and assembling data

61 views
Skip to first unread message

Davide Neri

unread,
Sep 1, 2015, 8:13:13 AM9/1/15
to OrientDB
Hi,
I am developing a web app on node.js and using OrientDB.
For some functionalities I need to make queries on a structure like this:

User (V)
Post (V)

author (E)

User -- author --› Post


And queries should retrieve the User(s) element(s) and the posts he is author of...all in the same structure:

[ {
    @rid: #9:1,
    @class: User,
    name: user1,
    posts: [ {
                   @rid: #10:1,
                   @class: Post,
                   name: post1
                 }, {
                   @rid: #10:2,
                   @class: Post,
                   name: post2
                 } ]
  }, {
    @rid: #9:2,
    @class: User,
    name: user2,
    posts: [ ... ]
  } ]


Basically, I'm currently doing this in 2 steps:

select * from User where ...

where I get something like:

[ {
    @rid: #9:1,
    @class: User,
    name: user1,
    out_author: [#10:1, #10:2]
  }, {
    @rid: #9:2,
    @class: User,
    name: user2,
    out_author: [#10:3, #10:3]
  } ]


From this result I collect all the rids of the first query and make a second query:

select expand(out('author')) from Post where @rid in [USERS_RIDS]

where I get something like:

[ {
    @rid: #10:1,
    @class: Post,
    name: post1
  }, {
    @rid: #10:2,
    @class: Post,
    name: post2
  } ]



And in the end I merge the results of the two queries by matching the @rids in out_author of the first results and @rids of the Posts in the second results.

This all works well, until I have just a few edges.. but when edges start to become more than 40 the out_author becomes blank...and my whole algorithm breaks. So here are my two questions:

- I was reading that to have more rids returned I need to change the RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD to a bigger number... I tried to change the orientdb-server-config.xml adding an entry in properties....but I can't see any results. I'm pretty sure I'm adding a wrong entry, but I can't understand any clear explanation of what I should do. Do you know what exactly should I do to change this value?

- Also... is there another better way to achieve the same result I need to have with my algorithm? Is it possible to be achieved with a single query or in some way that doesn't rely on matching rids?



Thank you very much for your help!


Message has been deleted

Johan Sjöberg

unread,
Sep 1, 2015, 8:47:14 AM9/1/15
to OrientDB
A better way could be:

select *, $posts 
from User 
let $posts = (select expand(in('author')) from $parent.$current)
where username = ..

The $parent.$current would be a specific user, you then expand the edge to the posts. Which you then return as $posts
Not entirely sure of the direction of you edge but I'm sure you figure it out!

I know nothing about RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD  thou.

/ Johan

Davide Neri

unread,
Sep 1, 2015, 10:01:44 AM9/1/15
to OrientDB
Wow, thank you,
I just tried it and this goes around the limit problem, so it is definitely a possible solution!

If anybody knows how to set the Rid Bag threshold higher, would be probably faster and lighter on the server as it would use only a simple query.
Otherwise at least for now I might implement this solution. Thanks again

[d]

Davide Neri

unread,
Sep 2, 2015, 11:06:00 AM9/2/15
to OrientDB
Heyhey,
With this query I'm able to get only the RIDs of the linked vertices going around the RID Bag limits, but I still need to fetch linked vertex with another query later.
I would have thought that, since there is an expand(in(...)) it would have returned the vertices and not their RIDs only, but I must be wrong : D

Do you know a way to have the result all in once, avoiding the use of a second query and nested loops?


Aaaand... otherwise, does anybody know how to change RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD value?

user.w...@gmail.com

unread,
Sep 2, 2015, 3:13:32 PM9/2/15
to OrientDB
Hi Davide,

Try this:

select *, @this.toJSON('rid,version,fetchPlan:[*]out_author:-1 [*]in_author*:-2') from User where name = "user1"


Regards,
Michela
Reply all
Reply to author
Forward
0 new messages