Skip to content

tessera_pg

Planner-hook join aggregation and item similarity using sparse matrix multiplication.

tessera_pg · Planner-hook join aggregation and item similarity using sparse matrix multiplication.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102301tessera_pgtessera_pg1.0OLAPApache-2.0C++

PostgreSQL · 18

Usage

Sources:

tessera_pg replaces supported join-aggregate plans with sparse matrix multiplication and exposes item-similarity functions. Distribution 1.4.4 installs SQL version 1.0. It targets PostgreSQL 18; the native engine requires OpenMP and AVX2 or newer on x86-64.

Core Workflow

Enable the planner hook in the session, then install the SQL functions:

LOAD 'tessera_pg';
CREATE EXTENSION tessera_pg;
CREATE TABLE edges (k bigint NOT NULL, x bigint NOT NULL);
INSERT INTO edges VALUES (1,10),(1,20),(2,10),(2,30);
EXPLAIN SELECT a.x, b.x, COUNT(*)
FROM edges a JOIN edges b ON a.k = b.k
GROUP BY a.x, b.x;
SELECT * FROM tessera_sim('edges', 'k', 'x', 'jaccard', 0.5);

Custom Scan (Tessera) identifies an accepted rewrite. Version 1.4.1 adds sums and counts over nullable columns, per-group top-k pruning with RANK() or ROW_NUMBER(), and multiple floating-point sums in one pass. A joined pair contributes to a sum only when all factors are non-NULL; a group without a contributing pair has a NULL sum. The adapter still supports COUNT(DISTINCT a.k), AVG, one-sided SUM, expression keys and grouping columns, input filters, HAVING and top-N pruning.

PostgreSQL leaves unsupported cases with its normal plan: nullable decimal weights, nullable float8 averages, integer-times-float8 products, real products, MIN, MAX, outer joins and nondeterministic collations. Multiple sums and nullable summed inputs also have restrictions on partitioned/inherited inputs or inputs with their own plans. Consult the versioned supported-query matrix; only PostgreSQL built-in operators and aggregates are recognized.

1.4.4 Runtime and Planner Fixes

Distribution 1.4.4 keeps SQL version 1.0 and the same C interface, but fixes PostgreSQL row-count estimates that could turn NOT EXISTS or group joins into a nested loop, restores CPU affinity after OpenMP load, and isolates AVX-512/AMX standard-library symbols on CPUs without those instructions. The release also improves Spark parallelism. It does not change the supported-query contract; continue to measure plans on the real workload.

Similarity Functions and Settings

tessera_sim returns bigint item pairs and a score; tessera_sim_text returns text pairs. Their arguments identify the relation, key and item columns, similarity measure, threshold, optional weight column, pair mode and thread count. Both are volatile and parallel-unsafe SQL functions.

tessera.enabled defaults on, tessera.threads defaults to 0, and tessera.frontier defaults to -1 for cost-model selection. Other controls include tessera.min_expansion, tessera.min_expansion_cross and tessera.trace. Default threading accounts for the leader and the query’s max_parallel_workers_per_gather workers.

Operational Boundaries

LOAD or session_preload_libraries activates the hook; a shared preload/restart is not mandatory. CREATE EXTENSION installs the relocatable SQL objects. Plan memory can reach work_mem * hash_mem_multiplier; spilling uses temp_tablespaces and remains subject to temp_file_limit. Measure execution plans, temporary disk and concurrency on the actual workload; source benchmarks do not guarantee production speedups.

Table reader