Oracle Spatial and Graph – technical tips, best practices, and news from the product team

  • December 8, 2020

Using graphs to understand relationships with Oracle Database 21c

James Steiner
Vice President

With all the information that resides in our databases and operational systems, you would think that it would be easy to answer questions about who our most important customers and suppliers are, where are the critical points in a supply chain, which business or financial transactions may be suspicious, and what patterns are visible in sales data.  But these kinds of questions, and others like them that are based on how data elements are connected to others, can be difficult to express and analyze using traditional methods.

Graphs let you model, explore and perform analysis on your data based on how it is related to other information.  Whether it is a hierarchy structure in a human capital management schema, more complex relationships across sales data, consumer data, and demographic data, near-real-time analysis of online payment patterns, or linked data in public sector institutions for citizens’ use, it is more natural to model these connections and relationships as a graph.


Oracle Database 21c makes it simpler to install, configure and deploy graph features with the Graph Server and Client Kit.  This simplified packaging makes it easier to deploy and develop Property Graph applications and includes a native SPARQL endpoint to query RDF graphs.

How to use Graphs in Oracle Database

Model data as a Graph

The first step in performing graph analysis is to model the data as a graph.  Data from tables can be modeled as a graph and stored in the property graph schema, and loaded into the in memory graph server (PGX) to run the high speed analytics algorithms.   Alternatively, data can be instantiated as a graph in PGX in memory directly from standard tables.    If the data is in files in a known graph format (GraphML, GraphSON, GML or the Oracle Flat File Format) it can directly be loaded into the property graph schema. Once data is represented as a graph, in the property graph schema or in PGX, you can query, run analyses and visualize the results.  For RDF graphs, a graph can be loaded from a variety of native RDF formats or created from relational tables using a W3C graph mapping standard.

Querying and visualizing graph data

Oracle Database has a graph query language, PGQL, that simplifies the expression of traversal queries commonly used to retrieve data from graphs.  These might be queries to answer questions like “What path did the funds in this account take before they were deposited?” or “How close are the personal relationships of our purchasing managers to our suppliers?”. 

PGQL is a SQL-like query language for property graph data structures.  The language is based on the concept of graph pattern matching, which allows you to specify patterns that are matched against vertices and edges in a data graph.  

Oracle Database 21c supports graph visualization tools that let you interactively explore the graph, customize layouts, and highlight interesting relationships in your data.   Seeing graph data and relationships visually lets analysts, data scientists, and developers quickly understand and explore clusters, outliers, anomalies, patterns, communities, and critical connections in their data. 

You can query the RDF Graph in Oracle Database using the W3C standard query language SPARQL or through a SPARQL endpoint, SPARQL-in-SQL, or a Java API.

Graph Algorithms to Perform Analysis

One of the benefits of graphs is that they give you the ability to apply algorithms to analyze the relationships in the data.  These go beyond pattern matching and traversal and allow you to assess things like the strength of relationships, the importance of data elements, and whether something is in a critical path or influences other people or processes.  

Oracle Database property graph includes nearly 60 out of the box graph analytic algorithms to let you do things like find communities and influences, discover anomalies and fraud, recommend products, discover complex patterns and analyze paths.  

These prebuilt, parallel algorithms enable you to perform churn risk analysis, targeted marketing, and HR turnover analysis, spam and fraud detection, product recommendation, and path analysis and reachability.

In Oracle Database 21c, you can create or extend graph algorithms using Java syntax, in addition to the dozens of pre-built graph analytics that come with the product.  These user-defined algorithms will execute as fast as native algorithms in the product because they are compiled with the same optimizations.  For unique and specialized use cases, customizing graph algorithms lets you add analysis that analysts and data scientists design specifically for your applications.   

Faster Performance with Optimized In-Memory graph models

Oracle Database 21c includes an optimized representation of a property graph that uses less memory when using the in-memory graph server (PGX).  PGX can execute complex graph queries in milliseconds on graphs containing billions of nodes and edges.  The optimized graph representation gives you faster performance and is transparent; existing applications will run faster with no change.

Client Tools

The rich set of features for graph database and analytics can be accessed through a Java or Python API executed in popular notebooks or in business applications, and by running PGQL queries in the graph visualization tool or the SQLCl client.   RDF graph developers can use the widely popular SQL Developer tool, or an Oracle JET based query UI.

Graph in Oracle Database 21c

Oracle wants every developer, every data scientist and anyone who uses Oracle Database to be able to use graph analytics, graph models, and graph querying of their data.  To enable this, Oracle is including all of the database graph capabilities, as well as the spatial and machine learning features, in Oracle Database at no additional cost.