跳转到主要内容

onesparse

Sparse linear algebra and graph extension for PostgreSQL 18

one_sparse : Sparse linear algebra and graph extension for PostgreSQL 18

Overview

ID Extension Package Version Category License Language
2620 onesparse one_sparse 0.1.0 FEAT Apache-2.0 C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-- No Yes Yes Yes no no
Relationships
Schemas onesparse
See Also age pg_liquid graph pgrdf ltree sparql
PG18; package 1.0.0 / SQL 0.1.0; preload onesparse. Rebuilt with GraphBLAS 10.5.2 and LAGraph 1.2.2.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.0 19 18 17 16 15 one_sparse -
RPM PIGSTY 1.0.0 19 18 17 16 15 onesparse_$v graphblas, lagraph
DEB PIGSTY 1.0.0 19 18 17 16 15 postgresql-$v-onesparse libgraphblas10, liblagraph1, liblagraphx1
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 1.0.0 N/A N/A N/A
el8.aarch64 N/A PIGSTY 1.0.0 N/A N/A N/A
el9.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
el9.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
el10.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
el10.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
d12.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
d12.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
d13.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
d13.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u22.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u22.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u24.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u24.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u26.x86_64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
u26.aarch64 PIGSTY 1.0.0 PIGSTY 1.0.0 N/A N/A N/A
Package Version OS ORG SIZE File URL
onesparse_19 1.0.0 el9.x86_64 pigsty 675.8 KiB onesparse_19-1.0.0-2PGSTY.el9.x86_64.rpm
onesparse_19 1.0.0 el9.aarch64 pigsty 665.9 KiB onesparse_19-1.0.0-2PGSTY.el9.aarch64.rpm
onesparse_19 1.0.0 el10.x86_64 pigsty 687.0 KiB onesparse_19-1.0.0-2PGSTY.el10.x86_64.rpm
onesparse_19 1.0.0 el10.aarch64 pigsty 673.3 KiB onesparse_19-1.0.0-2PGSTY.el10.aarch64.rpm
postgresql-19-onesparse 1.0.0 d12.x86_64 pigsty 596.4 KiB postgresql-19-onesparse_1.0.0-2PGSTY~bookworm_amd64.deb
postgresql-19-onesparse 1.0.0 d12.aarch64 pigsty 577.3 KiB postgresql-19-onesparse_1.0.0-2PGSTY~bookworm_arm64.deb
postgresql-19-onesparse 1.0.0 d13.x86_64 pigsty 592.7 KiB postgresql-19-onesparse_1.0.0-2PGSTY~trixie_amd64.deb
postgresql-19-onesparse 1.0.0 d13.aarch64 pigsty 576.7 KiB postgresql-19-onesparse_1.0.0-2PGSTY~trixie_arm64.deb
postgresql-19-onesparse 1.0.0 u22.x86_64 pigsty 695.4 KiB postgresql-19-onesparse_1.0.0-2PGSTY~jammy_amd64.deb
postgresql-19-onesparse 1.0.0 u22.aarch64 pigsty 683.5 KiB postgresql-19-onesparse_1.0.0-2PGSTY~jammy_arm64.deb
postgresql-19-onesparse 1.0.0 u24.x86_64 pigsty 645.6 KiB postgresql-19-onesparse_1.0.0-2PGSTY~noble_amd64.deb
postgresql-19-onesparse 1.0.0 u24.aarch64 pigsty 634.8 KiB postgresql-19-onesparse_1.0.0-2PGSTY~noble_arm64.deb
postgresql-19-onesparse 1.0.0 u26.x86_64 pigsty 658.2 KiB postgresql-19-onesparse_1.0.0-2PGSTY~resolute_amd64.deb
postgresql-19-onesparse 1.0.0 u26.aarch64 pigsty 642.0 KiB postgresql-19-onesparse_1.0.0-2PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
onesparse_18 1.0.0 el8.x86_64 pigsty 677.7 KiB onesparse_18-1.0.0-2PGSTY.el8.x86_64.rpm
onesparse_18 1.0.0 el8.aarch64 pigsty 656.3 KiB onesparse_18-1.0.0-2PGSTY.el8.aarch64.rpm
onesparse_18 1.0.0 el9.x86_64 pigsty 681.0 KiB onesparse_18-1.0.0-2PGSTY.el9.x86_64.rpm
onesparse_18 1.0.0 el9.aarch64 pigsty 669.4 KiB onesparse_18-1.0.0-2PGSTY.el9.aarch64.rpm
onesparse_18 1.0.0 el10.x86_64 pigsty 685.5 KiB onesparse_18-1.0.0-2PGSTY.el10.x86_64.rpm
onesparse_18 1.0.0 el10.aarch64 pigsty 673.0 KiB onesparse_18-1.0.0-2PGSTY.el10.aarch64.rpm
postgresql-18-onesparse 1.0.0 d12.x86_64 pigsty 596.7 KiB postgresql-18-onesparse_1.0.0-2PGSTY~bookworm_amd64.deb
postgresql-18-onesparse 1.0.0 d12.aarch64 pigsty 578.1 KiB postgresql-18-onesparse_1.0.0-2PGSTY~bookworm_arm64.deb
postgresql-18-onesparse 1.0.0 d13.x86_64 pigsty 593.5 KiB postgresql-18-onesparse_1.0.0-2PGSTY~trixie_amd64.deb
postgresql-18-onesparse 1.0.0 d13.aarch64 pigsty 578.4 KiB postgresql-18-onesparse_1.0.0-2PGSTY~trixie_arm64.deb
postgresql-18-onesparse 1.0.0 u22.x86_64 pigsty 694.4 KiB postgresql-18-onesparse_1.0.0-2PGSTY~jammy_amd64.deb
postgresql-18-onesparse 1.0.0 u22.aarch64 pigsty 683.0 KiB postgresql-18-onesparse_1.0.0-2PGSTY~jammy_arm64.deb
postgresql-18-onesparse 1.0.0 u24.x86_64 pigsty 645.7 KiB postgresql-18-onesparse_1.0.0-2PGSTY~noble_amd64.deb
postgresql-18-onesparse 1.0.0 u24.aarch64 pigsty 635.4 KiB postgresql-18-onesparse_1.0.0-2PGSTY~noble_arm64.deb
postgresql-18-onesparse 1.0.0 u26.x86_64 pigsty 658.0 KiB postgresql-18-onesparse_1.0.0-2PGSTY~resolute_amd64.deb
postgresql-18-onesparse 1.0.0 u26.aarch64 pigsty 642.2 KiB postgresql-18-onesparse_1.0.0-2PGSTY~resolute_arm64.deb

Source

pig build pkg one_sparse;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install one_sparse;		# install via package name, for the active PG version
pig install onesparse;		# install by extension name, for the current active PG version

pig install onesparse -v 19;   # install for PG 19
pig install onesparse -v 18;   # install for PG 18

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'onesparse';

Create this extension with:

CREATE EXTENSION onesparse;

Usage

Sources: homepage, release v1.0.0, control file at v1.0.0, intro docs, matrix docs, vector docs, algorithm examples

OneSparse is a PostgreSQL extension that binds SuiteSparse:GraphBLAS into Postgres and exposes sparse linear algebra and graph algorithms as new types, functions, and operators. The docs treat matrix as the core type, with vector and scalar built on top of the same model. The v1.0.0 release exists, while the extension control file at that tag still declares SQL default_version = '0.1.0'.

Core Setup

CREATE EXTENSION onesparse;
SET search_path TO public,onesparse;

SELECT 'int32'::matrix;
SELECT 'int32'::vector;
SELECT 'int32:42'::scalar;

The docs site organizes the API around matrix, vector, and scalar, with interactive examples using casts and constructors.

Matrix and Vector

The matrix page shows common operations such as construction, print(), draw(), assignment, extraction, cast_to(), resize, and aggregation. The vector page documents the matching vector API including nvals(), size(), eadd(), emult(), reduce_scalar(), choose(), and apply().

SELECT print('int32(4:4)'::matrix);
SELECT draw('int32(4:4)[1:2:1 2:3:2 3:1:3]'::matrix);
SELECT eadd('int32[0:1 1:2 2:3]'::vector, 'int32[0:1 1:2 2:3]'::vector, 'plus_int32');
SELECT reduce_scalar('int32[0:1 1:2 2:3]'::vector, 'plus_monoid_int32');

Graph Algorithms

The examples page uses Matrix Market input and graph visualization with draw(...). The documented graph algorithms include:

  • bfs(graph, 1) for level and parent BFS
  • sssp(cast_to(graph, 'int32'), 1::bigint, 1) for single-source shortest path
  • pagerank(graph) for ranking vertices by link structure
  • triangle_centrality(graph) for triangle-based centrality
  • betweenness(graph, ARRAY[...]) and square_clustering(graph) for additional graph analysis

Representative example from the docs:

SELECT draw(triu(graph), (SELECT level FROM bfs(graph, 1)), false, false, true, 0.5)
FROM karate;

The same guide shows loading a graph with mmread('/home/postgres/onesparse/demo/karate.mtx').

表格阅读器