Consider tree like graph represented by "Node" verticies and "childOf" edges (oriented from child to parent) and command:
Iterable<OrientVertex> roots = (Iterable<OrientVertex>) graph.command(new OCommandSQL("select from Node where key = 'root' fetchplan in_childOf:-1")).execute();
Now when I traverse the tree by Vertex.getVerticies(Direction.IN, "childOf")/ODocument.field("in_childOf") I expect there won't be any further remote lookup calls, because verticies have been already fetched by fetch plan.
But is it really the case?
I was trying to find out how accessing related records (edges) works:
The edges are represented as ORidBag:
ORidBag ridBag = (ORidBag) root.getRecord().field("in_childOf");
The ORidBag is a collection of OIdentifiable implemented by ORecordId:
ORecordId rid = (ORecordId) ridBag.iterator().next();
Now I can access the record (implemented by ODocument) representing the edge:
ODocument inChild = (ODocument) rid.getRecord();
The implementation of ORecordId.getRecord() is quite simple. It basically delegates the record retrieval to current ODatabaseDocument implemented by ODatabaseDocumentTx:
return (T) db.load(this);
There the things are getting complicated, but if I summarize my foundings, the record is either taken from local cache or requested to be fetched by OStorageRemote.
As you can see I was able to find out only one place where the related record is not requested from the storage again and that is obtaining a record from local cache by ODatabaseDocumentTx.
However I checked that the related records are not present in local cache after the command is executed, so local cache also isn't responsible for accessing eagerly fetched records.
So am I really working with fetched records or are they fetched again when traversing graph with Document/Graph API in remote mode?
Which component (ODocument/ORidBag/ODatabase/OStorage) is responsible for obtaining a record which is possibly loaded eagerly via fetch plan?
And is there a way to tell if the related record (represented for example by ORecordId) is already fetched?
According to some forum posts the eagerly fetched records should be stored in 2nd level client cache, I wonder how do I access that cache?
Since orientdb 2.0, there is only one local cache, but as I mentioned earlier, it does not contain the verticies/edges after the command is executed (they are present in the cache only after I visit them manually - via traversal methods), is this unexpected behavior?