sqloracle-databaseproperty-graphoracle-graph

How to write a query for path lengths greater than 10 using Oracle SQL Property Graph?


I am translating the query below from PGQL to SQL:

PGQL:

SELECT DISTINCT b.name
FROM MATCH (a:person) -/:friends*/-> (b:person) ON students_graph
WHERE a.name='Mary';

SQL:

SELECT DISTINCT name FROM GRAPH_TABLE (students_graph
  MATCH (a is person WHERE a.name='Mary') -[is friends]->{,*} (b is person)
  COLUMNS (b.name)
);

However, the maximum upper bound limit of the path length is 10, and * is not allowed in the current PGQ/SQL implementation (in 24.3).

Is there any way to increase or eliminate the upper bound limit?


Solution

  • There is a system parameter you can set to extend the upper limit. Here is an example:

    alter session set "_quantified_path_pattern_maximum_upper_bound"=12
    

    You can use it to progressively increase the maximum number of hops until no new path is discovered. This is how you can emulate *.

    Note: One issue here is that -/:friends*/-> in PGQL finds ANY path for each a and b. While -[is friends]->{,10} finds ALL paths up to 10 hops for each a and b. Finding ALL paths has exponential results, so increasing this to anything higher than a few hops will likely be very slow. Even five hops may already become very slow. Adding DISTINCT will ensure you get the same final result, but the computation required for these two queries is very different. There is no way to find ANY path yet in SQL/PGQ, although work is underway to add this (in the form of ANY SHORTEST path).