7.1 Overview of a Graph Algorithm Function

Graph algorithm functions (GAFs) are Oracle-supplied PL/SQL functions in the DBMS_OGA package, which is available in the database.

A GAF is a function that takes a SQL property graph as input and returns a new property graph as output. The new graph is based on the same set of vertex and edge tables as the input graph, but it includes additional properties that store the algorithm results. This output graph is then passed as the first argument to a GRAPH_TABLE operator in a SQL query.

As a result, the GRAPH_TABLE operator can access all the labels and properties defined in the input graph, as well as the new properties created by the GAF. However, the new properties and the derived property graph produced by the GAF are available only within the SQL cursor in which the GAF appears; both are discarded at the end of the cursor execution.

Also, note the following:

  • Different users can execute the same graph algorithm concurrently, on the same graph or on different graphs.
  • Multiple sessions can run the same SQL query at the same time when it includes a graph algorithm function, enabling cursor sharing.

See DBMS_OGA in Oracle AI Database PL/SQL Packages and Types Reference for more information.

The following example shows how to run the pagerank algorithm on graph g. It then returns, for each Person vertex, the person's name and the computed PageRank score.

SELECT *
FROM GRAPH_TABLE(
  pagerank(
    g,
    PROPERTY(VERTEX OUTPUT rank)
  )
  MATCH (v IS Person)
  COLUMNS (
    v.name,
    v.rank
  )
) ORDER BY rank DESC;