tessera_pg

This Release
tessera_pg 1.2.1
Date
Status
Stable
Abstract
Fast join-aggregates over skewed sparse relations inside PostgreSQL
Description
A planner hook that runs join-aggregates such as SELECT a.x, b.x, COUNT(*) FROM r a JOIN r b ON a.k = b.k GROUP BY a.x, b.x, with weights, HAVING, and two relations, as a sparse matrix product with exact results, plus functions for item similarity.
Released By
Gyuyeong
License
Apache 2.0
Resources
Special Files
Tags

Extensions

tessera_pg 1.0.0
Join-aggregate operator and item similarity

README

tessera_pg

Tessera for PostgreSQL: fast join-aggregates over skewed sparse relations, with exact results. A join-aggregate counts or sums the joined rows of each pair of values:

SELECT a.x, b.x, COUNT(*) FROM r a JOIN r b ON a.k = b.k GROUP BY a.x, b.x;

PostgreSQL runs it as a hash join and a hash aggregation, which builds one joined row for every two rows that share a key. Tessera’s planner hook replaces that part of the plan with a sparse matrix product, so the SQL stays unchanged. It also handles SUM(a.v * b.v), a.x < b.x, HAVING, and the product of two relations.

Install

PostgreSQL 18 with its server headers, a C and C++ compiler with OpenMP (GCC), and make. On x86-64 the extension needs an AVX2 CPU or newer.

pgxn install tessera_pg

or, from this directory, make && make install.

Use

LOAD 'tessera_pg';                -- or session_preload_libraries = 'tessera_pg'
CREATE EXTENSION tessera_pg;      -- adds tessera_sim and tessera_sim_text
SELECT a.x, b.x, COUNT(*) FROM r a JOIN r b ON a.k = b.k GROUP BY a.x, b.x;
SELECT * FROM tessera_sim('r', 'k', 'x', 'jaccard', 0.5);

EXPLAIN shows Custom Scan (Tessera) where Tessera runs. Tessera takes a query only when valid NOT NULL constraints show that its grouped and summed columns hold no NULLs. Settings: tessera.enabled (on), tessera.threads (0: the leader and max_parallel_workers_per_gather workers of one query), tessera.frontier (-1: cost model), tessera.min_expansion and tessera.min_expansion_cross (0), and tessera.trace. The output may use work_mem * hash_mem_multiplier in memory, and the rest goes to temp_tablespaces within temp_file_limit.

Supported queries, the DuckDB, SQLite, and Spark adapters, and the C interface: https://github.com/GyuyeongKim/Tessera-public