Performance Issue with Inferred Relationship


#1

Below given is a schema with profiles, posts and comments.
In plain terms, profiles contain posts. Posts contain comments. Comments contain Comments.

facebookID is the ID of an object itself. objectId is the ID of the enclosing object.

:

define

authorship
    sub relationship,
    relates author,
    relates authored,
    relates object;
author sub role;
authored sub role;
object sub role;

node sub entity;
facebookId sub attribute datatype string;
objectId sub attribute datatype string;

profile
    sub node,
    plays author,
    plays object,
    has facebookId;

post
    sub node,
    plays authored,
    plays object,
    has facebookId,
    has objectId;

comment
    sub node,
    plays authored,
    plays object,
    has facebookId,
    has objectId;

authored_object sub rule
when {
    $object has facebookId $objectId;
    $authored has objectId $authoredObjectId;
    $authoredObjectId val = $objectId;
}
then {
    (object: $object, authored: $authored) isa authorship;
};

I have a really small dataset on my machine:

>>> match $x isa profile; aggregate count;
30
>>> match $x isa post; aggregate count;
738
>>> match $x isa comment; aggregate count;
584

I get a really slow response, when I know ask for

match $x isa authorship; limit 20; get;

On my machine, this takes 20 seconds.