Skip to content
pg_regresql

pg_regresql

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

Overview

ID Extension Package Version Category License Language
3230
pg_regresql
pg_regresql
2.0.0
LANG
BSD-2-Clause
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-r
No
Yes
Yes
Yes
yes
no
Relationships
See Also
pg_hint_plan
hypopg
plan_filter
auto_explain

Activate it with LOAD pg_regresql or session_preload_libraries.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
2.0.0
18
17
16
15
14
pg_regresql -
RPM
PIGSTY
2.0.0
18
17
16
15
14
pg_regresql_$v -
DEB
PIGSTY
2.0.0
18
17
16
15
14
postgresql-$v-pg-regresql -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el8.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el9.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el9.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el10.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el10.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d12.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d12.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d13.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d13.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u22.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u22.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u24.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u24.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u26.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u26.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
Package Version OS ORG SIZE File URL
pg_regresql_18 2.0.0 el8.x86_64 pigsty 10.7 KiB pg_regresql_18-2.0.0-1PIGSTY.el8.x86_64.rpm
pg_regresql_18 2.0.0 el8.aarch64 pigsty 10.9 KiB pg_regresql_18-2.0.0-1PIGSTY.el8.aarch64.rpm
pg_regresql_18 2.0.0 el9.x86_64 pigsty 10.4 KiB pg_regresql_18-2.0.0-1PIGSTY.el9.x86_64.rpm
pg_regresql_18 2.0.0 el9.aarch64 pigsty 10.4 KiB pg_regresql_18-2.0.0-1PIGSTY.el9.aarch64.rpm
pg_regresql_18 2.0.0 el10.x86_64 pigsty 10.4 KiB pg_regresql_18-2.0.0-1PIGSTY.el10.x86_64.rpm
pg_regresql_18 2.0.0 el10.aarch64 pigsty 10.6 KiB pg_regresql_18-2.0.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-regresql 2.0.0 d12.x86_64 pigsty 8.1 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-regresql 2.0.0 d12.aarch64 pigsty 8.2 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-regresql 2.0.0 d13.x86_64 pigsty 8.1 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-regresql 2.0.0 d13.aarch64 pigsty 8.2 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-regresql 2.0.0 u22.x86_64 pigsty 8.6 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-regresql 2.0.0 u22.aarch64 pigsty 8.3 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-regresql 2.0.0 u24.x86_64 pigsty 8.4 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-regresql 2.0.0 u24.aarch64 pigsty 8.3 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~noble_arm64.deb
postgresql-18-pg-regresql 2.0.0 u26.x86_64 pigsty 8.3 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-regresql 2.0.0 u26.aarch64 pigsty 8.4 KiB postgresql-18-pg-regresql_2.0.0-1PIGSTY~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 via package name, for the active PG version

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
pig install pg_regresql -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_regresql';

Create this extension with:

CREATE EXTENSION pg_regresql;

Usage

Sources: extension README, control file, portable stats article

pg_regresql is the PostgreSQL planner-hook part of RegreSQL. It makes the planner trust pg_class statistics instead of rescaling estimates from the physical file size, which is useful for plan regression testing with injected production statistics.

Activate the hook

LOAD 'pg_regresql';

EXPLAIN SELECT ...;

For a whole test instance, upstream recommends:

session_preload_libraries = 'pg_regresql'

What it overrides

The upstream README says the hook runs after estimate_rel_size() and replaces planner estimates with catalog values:

  • rel->pages from pg_class.relpages
  • rel->tuples from pg_class.reltuples
  • rel->allvisfrac from pg_class.relallvisible / relpages
  • IndexOptInfo->pages from index pg_class.relpages
  • IndexOptInfo->tuples from index pg_class.reltuples

Typical workflow

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

LOAD 'pg_regresql';

EXPLAIN SELECT * FROM test_orders WHERE created_at > '2024-06-01';

This is meant for reproducing production plans locally and for migration or upgrade plan-regression tests.

Notes

  • The control file currently declares default_version = '2.0'.
  • The public repository tags visible upstream are still v2.0.0-alpha*, so the packaged 2.0.0 target is ahead of a clearly tagged final GitHub release.
  • Upstream documents PostgreSQL 14+ compatibility for the extension.
Last updated on