OQGRAPH documentation

Install OQGRAPH, bind a backing table, and run path, reachability, and leaf queries.

OQGRAPH computes paths, reachability, and leaves over an edge table stored in a normal engine. You write edges to the backing table. You query algorithms through ENGINE=OQGRAPH.

Install

INSTALL SONAME 'ha_oqgraph';
SHOW ENGINES;

Distro packages differ (mariadb-plugin-oqgraph, MariaDB-oqgraph-engine, versioned names). Load the plugin after the package is installed. Confirm support is YES.

Minimal schema

CREATE TABLE oq_backing (
  origid INT UNSIGNED NOT NULL,
  destid INT UNSIGNED NOT NULL,
  PRIMARY KEY (origid, destid),
  KEY (destid)
);

INSERT INTO oq_backing (origid, destid) VALUES
  (1,2),(2,3),(3,4),(4,5),(2,6),(5,6);

CREATE TABLE oq_graph (
  latch VARCHAR(32) NULL,
  origid BIGINT UNSIGNED NULL,
  destid BIGINT UNSIGNED NULL,
  weight DOUBLE NULL,
  seq BIGINT UNSIGNED NULL,
  linkid BIGINT UNSIGNED NULL,
  KEY (latch, origid, destid) USING HASH,
  KEY (latch, destid, origid) USING HASH
) ENGINE=OQGRAPH
  data_table='oq_backing' origid='origid' destid='destid';

Wrong column types or missing engine options fail with create-option errors. Prefer VARCHAR latch; integer latch is deprecated.

Weighted edges

CREATE TABLE oq2_backing (
  origid INT UNSIGNED NOT NULL,
  destid INT UNSIGNED NOT NULL,
  weight DOUBLE NOT NULL,
  PRIMARY KEY (origid, destid),
  KEY (destid)
);

CREATE TABLE oq2_graph (
  latch VARCHAR(32) NULL,
  origid BIGINT UNSIGNED NULL,
  destid BIGINT UNSIGNED NULL,
  weight DOUBLE NULL,
  seq BIGINT UNSIGNED NULL,
  linkid BIGINT UNSIGNED NULL,
  KEY (latch, origid, destid) USING HASH,
  KEY (latch, destid, origid) USING HASH
) ENGINE=OQGRAPH
  data_table='oq2_backing'
  origid='origid' destid='destid' weight='weight';

Latch reference

latchpredicatesresult
NULLRaw edges
dijkstrasorigid, destidShortest path; linkid ordered by seq
dijkstrasorigid onlyReachable set + path weight sums
dijkstrasdestid onlyNodes that can reach destid
breadth_firstorigid / destid / bothBFS reachability or unweighted shortest path
leavesorigid or destidTerminal nodes; both predicates unsupported

Queries

SELECT GROUP_CONCAT(linkid ORDER BY seq) AS path
FROM oq_graph
WHERE latch='dijkstras' AND origid=1 AND destid=6;

SELECT GROUP_CONCAT(linkid) AS reachable
FROM oq_graph
WHERE latch='breadth_first' AND origid=2;

SELECT * FROM oq_graph WHERE latch='leaves' AND origid=2;

Operational notes

  • Query cache is not used by OQGRAPH
  • Edges are directed; model reverse arcs explicitly
  • Backup the backing table with the rest of the schema

Product: /products/graph-engine · Examples: worked examples