The fastest way to query edges

96 views
Skip to first unread message

Andrey Yesyev

unread,
Mar 6, 2014, 9:34:04 AM3/6/14
to orient-...@googlegroups.com
Hi there,

I need to find an edge between 2 vertices. In my schema there can be only one edge between 2 vertices.
I tried this 2 options

1. Using query

select from RELATED where in = :target and out = :src

RELATED is a class of the edge I'm looking for. 

2. Using API

vSrc.getEdges(vTarget, Direction.BOTH, RelationType.RELATED.name())

Both are extremely slow. My guess is because query goes over all RELATED edges, checking conditions for each of them.
I feel like I have to use TRAVERSE, but I can't come up with a query to do this.
Please help!

Thanks!
-Andrey

Andrey Yesyev

unread,
Mar 6, 2014, 10:41:55 AM3/6/14
to orient-...@googlegroups.com
I'll proceed with my search.

Now, I try to use index for edge, here is how I created it

OrientEdgeType edgeType = graph.createEdgeType(RelationType.RELATED.name());
edgeType.createProperty("in", OType.LINK);
edgeType.createProperty("out", OType.LINK);
edgeType.createIndex("relations", OClass.INDEX_TYPE.UNIQUE, "in", "out");

so, I changed my query to use this index

select from index:relations where Key = [ :target, :src ] or Key = [ :src, :target ]

but execution of this query throws an exception

com.orientechnologies.orient.core.exception.OCommandExecutionException: 'Key' field is required for queries against indexes
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchInIndex(OCommandExecutorSQLSelect.java:1127)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.assignTarget(OCommandExecutorSQLSelect.java:358)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:330)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:315)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:57)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.executeCommand(OStorageEmbedded.java:96)

What's wrong with it?




Andrey Yesyev

unread,
Mar 6, 2014, 11:23:33 AM3/6/14
to orient-...@googlegroups.com
Okay, looks like everything after OR was excessive.
Query works in this shape

select from index:relations where key = [ :target, :src ]

Using index, performance improved 10 times. 
Not bad.

ste...@activitystream.com

unread,
Mar 6, 2014, 4:53:07 PM3/6/14
to orient-...@googlegroups.com
Hi,

Out of curiosity, why are you creating a in/out property for the edge manually?

Regards,
 -Stefan

Andrey Yesyev

unread,
Mar 6, 2014, 6:23:35 PM3/6/14
to orient-...@googlegroups.com

Hm, good question. I found a post here, where I saw how the author of that post did, so I just copy/past it. I'll try to do this without it. Or maybe someone from orienttechnologies will comment on it.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/QUUVnVQ9x8g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andrey Yesyev

unread,
Mar 7, 2014, 8:31:00 AM3/7/14
to orient-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages