Identifying multigraph subgraphs

Hi, I’m sure this is a complete noob question… but equally sure the answer will make a major penny drop for me.

Is there a query that will return pairs of vertices that have multiple (i.e., > 1) edges and/or links connecting them to each other?

Lots of SQL and noSQL experience and some Neo4j/Cypher… but at this point I almost feel those paradigms are standing in my way! :smiley:

Thanks!

Hi @jpgringo

The following should work fine:

SELECT FROM (
  MATCH
    {class:V, as:a} .bothE(){as:edge}.bothV() {as:b, where:($matched.a != $currentMatch)}
  RETURN a, b, count(edge) as edgeCount
  GROUP BY a, b
) WHERE edgeCount > 1

I didn’t try it, so maybe it needs some small corrections, but I guess you got the point
(and don’t expect it to be a cheap query, it could take some time on big graphs)

Thanks

Luigi

An alternative could be

 SELECT FROM (
     SELECT out, in, count(*) as count from E GROUP BY in, out
 ) WHERE count > 1

Hi, Luigi… that’s amazing. I pretty much understand the second one, am presently confused by the first… but that’s the whole point. The second works as is, the first throws an error which I’m keen to solve on my own. So not only is my immediate problem solved, I’m going to learn a ton by dissecting these. Thanks.

I’m curious re performance:

  • on a large graph, would specifying classes (rather than V and E) probably speed things up?
  • in general would it be advisable to first select a subgraph based on a more efficient query and then query that subgraph?

Not relevant to my problem at hand (pretty small data set) but I want to make sure I’m grasping the OrientDB paradigm and underlying mechanics properly.

Thanks again,
Rick