Skip to content

pg_regresql

Trust pg_class statistics for planning instead of physical relation size

pg_regresql · Trust pg_class statistics for planning instead of physical relation size

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3230pg_regresqlpg_regresql2.2.1LANGBSD-2-ClauseC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Load via LOAD or session_preload_libraries.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY2.2.119 18 17 16 15pg_regresql-
RPMPIGSTY2.2.119 18 17 16 15pg_regresql_$v-
DEBPIGSTY2.2.119 18 17 16 15postgresql-$v-pg-regresql-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
el8.aarch64N/APIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
el9.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
el9.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
el10.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
el10.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
d12.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
d12.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
d13.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
d13.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u22.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u22.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u24.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u24.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u26.x86_64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
u26.aarch64PIGSTY 2.2.1PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0PIGSTY 2.2.0
PackageVersionOSORGSIZEFile URL
pg_regresql_192.2.1el9.x86_64pigsty26.3 KiBpg_regresql_19-2.2.1-1PGSTY.el9.x86_64.rpm
pg_regresql_192.2.1el9.aarch64pigsty26.2 KiBpg_regresql_19-2.2.1-1PGSTY.el9.aarch64.rpm
pg_regresql_192.2.1el10.x86_64pigsty26.2 KiBpg_regresql_19-2.2.1-1PGSTY.el10.x86_64.rpm
pg_regresql_192.2.1el10.aarch64pigsty26.3 KiBpg_regresql_19-2.2.1-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-regresql2.2.1d12.x86_64pigsty12.8 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-regresql2.2.1d12.aarch64pigsty12.8 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-regresql2.2.1d13.x86_64pigsty12.8 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~trixie_amd64.deb
postgresql-19-pg-regresql2.2.1d13.aarch64pigsty12.8 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~trixie_arm64.deb
postgresql-19-pg-regresql2.2.1u22.x86_64pigsty13.4 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~jammy_amd64.deb
postgresql-19-pg-regresql2.2.1u22.aarch64pigsty13.5 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~jammy_arm64.deb
postgresql-19-pg-regresql2.2.1u24.x86_64pigsty13.2 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~noble_amd64.deb
postgresql-19-pg-regresql2.2.1u24.aarch64pigsty13.2 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~noble_arm64.deb
postgresql-19-pg-regresql2.2.1u26.x86_64pigsty13.3 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~resolute_amd64.deb
postgresql-19-pg-regresql2.2.1u26.aarch64pigsty13.4 KiBpostgresql-19-pg-regresql_2.2.1-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_regresql_182.2.0el8.x86_64pigsty90.5 KiBpg_regresql_18-2.2.0-1PGSTY.el8.x86_64.rpm
pg_regresql_182.2.0el8.aarch64pigsty88.3 KiBpg_regresql_18-2.2.0-1PGSTY.el8.aarch64.rpm
pg_regresql_182.2.0el9.x86_64pigsty91.0 KiBpg_regresql_18-2.2.0-1PGSTY.el9.x86_64.rpm
pg_regresql_182.2.0el9.aarch64pigsty89.3 KiBpg_regresql_18-2.2.0-1PGSTY.el9.aarch64.rpm
pg_regresql_182.2.0el10.x86_64pigsty91.3 KiBpg_regresql_18-2.2.0-1PGSTY.el10.x86_64.rpm
pg_regresql_182.2.0el10.aarch64pigsty89.3 KiBpg_regresql_18-2.2.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-regresql2.2.0d12.x86_64pigsty75.4 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-regresql2.2.0d12.aarch64pigsty73.2 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-regresql2.2.0d13.x86_64pigsty75.6 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-regresql2.2.0d13.aarch64pigsty73.3 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-regresql2.2.0u22.x86_64pigsty81.4 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-regresql2.2.0u22.aarch64pigsty79.8 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-regresql2.2.0u24.x86_64pigsty78.5 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-regresql2.2.0u24.aarch64pigsty76.7 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-regresql2.2.0u26.x86_64pigsty77.8 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-regresql2.2.0u26.aarch64pigsty76.2 KiBpostgresql-18-pg-regresql_2.2.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_regresql_172.2.0el8.x86_64pigsty106.6 KiBpg_regresql_17-2.2.0-1PGSTY.el8.x86_64.rpm
pg_regresql_172.2.0el8.aarch64pigsty103.8 KiBpg_regresql_17-2.2.0-1PGSTY.el8.aarch64.rpm
pg_regresql_172.2.0el9.x86_64pigsty107.7 KiBpg_regresql_17-2.2.0-1PGSTY.el9.x86_64.rpm
pg_regresql_172.2.0el9.aarch64pigsty105.6 KiBpg_regresql_17-2.2.0-1PGSTY.el9.aarch64.rpm
pg_regresql_172.2.0el10.x86_64pigsty108.0 KiBpg_regresql_17-2.2.0-1PGSTY.el10.x86_64.rpm
pg_regresql_172.2.0el10.aarch64pigsty105.6 KiBpg_regresql_17-2.2.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-regresql2.2.0d12.x86_64pigsty91.2 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-regresql2.2.0d12.aarch64pigsty88.0 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-regresql2.2.0d13.x86_64pigsty91.5 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-regresql2.2.0d13.aarch64pigsty88.5 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-regresql2.2.0u22.x86_64pigsty116.5 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-regresql2.2.0u22.aarch64pigsty114.4 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-regresql2.2.0u24.x86_64pigsty95.0 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-regresql2.2.0u24.aarch64pigsty93.1 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-regresql2.2.0u26.x86_64pigsty94.7 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-regresql2.2.0u26.aarch64pigsty92.5 KiBpostgresql-17-pg-regresql_2.2.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_regresql_162.2.0el8.x86_64pigsty106.5 KiBpg_regresql_16-2.2.0-1PGSTY.el8.x86_64.rpm
pg_regresql_162.2.0el8.aarch64pigsty103.4 KiBpg_regresql_16-2.2.0-1PGSTY.el8.aarch64.rpm
pg_regresql_162.2.0el9.x86_64pigsty107.5 KiBpg_regresql_16-2.2.0-1PGSTY.el9.x86_64.rpm
pg_regresql_162.2.0el9.aarch64pigsty105.2 KiBpg_regresql_16-2.2.0-1PGSTY.el9.aarch64.rpm
pg_regresql_162.2.0el10.x86_64pigsty107.8 KiBpg_regresql_16-2.2.0-1PGSTY.el10.x86_64.rpm
pg_regresql_162.2.0el10.aarch64pigsty105.2 KiBpg_regresql_16-2.2.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-regresql2.2.0d12.x86_64pigsty91.1 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-regresql2.2.0d12.aarch64pigsty87.8 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-regresql2.2.0d13.x86_64pigsty91.3 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-regresql2.2.0d13.aarch64pigsty88.1 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-regresql2.2.0u22.x86_64pigsty114.8 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-regresql2.2.0u22.aarch64pigsty112.4 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-regresql2.2.0u24.x86_64pigsty95.0 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-regresql2.2.0u24.aarch64pigsty92.7 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-regresql2.2.0u26.x86_64pigsty94.6 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-regresql2.2.0u26.aarch64pigsty92.3 KiBpostgresql-16-pg-regresql_2.2.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_regresql_152.2.0el8.x86_64pigsty25.5 KiBpg_regresql_15-2.2.0-1PGSTY.el8.x86_64.rpm
pg_regresql_152.2.0el8.aarch64pigsty25.7 KiBpg_regresql_15-2.2.0-1PGSTY.el8.aarch64.rpm
pg_regresql_152.2.0el9.x86_64pigsty25.7 KiBpg_regresql_15-2.2.0-1PGSTY.el9.x86_64.rpm
pg_regresql_152.2.0el9.aarch64pigsty25.7 KiBpg_regresql_15-2.2.0-1PGSTY.el9.aarch64.rpm
pg_regresql_152.2.0el10.x86_64pigsty25.7 KiBpg_regresql_15-2.2.0-1PGSTY.el10.x86_64.rpm
pg_regresql_152.2.0el10.aarch64pigsty25.8 KiBpg_regresql_15-2.2.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-regresql2.2.0d12.x86_64pigsty12.5 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-regresql2.2.0d12.aarch64pigsty12.6 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-regresql2.2.0d13.x86_64pigsty12.5 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-regresql2.2.0d13.aarch64pigsty12.6 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-regresql2.2.0u22.x86_64pigsty14.0 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-regresql2.2.0u22.aarch64pigsty14.1 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-regresql2.2.0u24.x86_64pigsty12.9 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-regresql2.2.0u24.aarch64pigsty12.9 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-regresql2.2.0u26.x86_64pigsty13.0 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-regresql2.2.0u26.aarch64pigsty13.2 KiBpostgresql-15-pg-regresql_2.2.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_regresql;		# 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 pg_regresql;		# install by package name

pig install pg_regresql -v 19;   # install for PG 19
pig install pg_regresql -v 18;   # install for PG 18
pig install pg_regresql -v 17;   # install for PG 17
pig install pg_regresql -v 16;   # install for PG 16
pig install pg_regresql -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_regresql';

Create this extension with:

CREATE EXTENSION pg_regresql;

Usage

Sources:

pg_regresql makes query planning use catalog statistics instead of rescaling them from physical file size. This supports plan regression tests in databases with representative statistics but little data. Release 2.2.1 installs its SQL objects in the fixed pg_catalog schema.

Activate the Planner Hook

The hook supports PostgreSQL 15 or later. Load it as a superuser in the test session:

LOAD 'pg_regresql';
CREATE TABLE test_orders (created_at date);
EXPLAIN SELECT * FROM test_orders WHERE created_at > DATE '2024-06-01';

For new sessions on a test instance, add the library to the existing session preload list:

session_preload_libraries = 'pg_regresql'

The hook replaces table and index page/tuple estimates with pg_class values and computes visibility from catalog statistics. Inject useful statistics before comparing plans; an empty table alone is not a production workload.

Restore Statistics

On PostgreSQL 16 and 17, create the extension before loading statistics emitted by a recent pg_dump:

CREATE EXTENSION pg_regresql;
SELECT pg_restore_relation_stats(
    'schemaname', 'public', 'relname', 'test_orders',
    'relpages', 123513::integer, 'reltuples', 50000000::real,
    'relallvisible', 123513::integer
);

Version 2.2 adds pg_restore_extended_stats() and pg_clear_extended_stats() for those servers, and supports the JSON input emitted by pg_dump 19 for pg_ndistinct and pg_dependencies. On PostgreSQL 16 remove the dump’s unsupported transaction_timeout setting. PostgreSQL 18 already supplies relation/attribute restoration in core; extended restoration is in core from 19. The extension does not install these backports on 18 or later.

Upgrade and Cleanup

From SQL version 2.0, upstream requires dropping and recreating the extension. From 2.1, use ALTER EXTENSION pg_regresql UPDATE. Review dependencies before removing it. The extension is not relocatable and its install requires a superuser.

The replacement input functions named regresql_pg_*_in are deliberately detached from the extension on 16/17. DROP EXTENSION leaves them behind so the installed casts keep working; dropping the extension is therefore not a complete return to the original catalog state. Use this tool in controlled planning tests, and do not assume compatibility with other planner hooks has been tested.

PostgreSQL 19 Planner Hook

Release 2.2.1 uses build_simple_rel_hook on PostgreSQL 19 and get_relation_info_hook on earlier supported majors. After installing the matching files, run ALTER EXTENSION pg_regresql UPDATE TO '2.2.1'; on installations using 2.2. This update advances the recorded extension version and preserves the existing SQL definitions.

Table reader