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.2.1 |
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 | hypopg pg_qualstats pg_hint_plan online_advisor index_advisor pg_stat_plans plan_filter pg_track_optimizer pg_strom pg_orca |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| el8.aarch64 | N/A | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| el9.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| el9.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| el10.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| el10.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| d12.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| d12.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| d13.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| d13.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u22.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u22.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u24.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u24.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u26.x86_64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
| u26.aarch64 | MISS | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 | PIGSTY 2.2.0 |
Source
github.com/boringsql/regresql
pg_regresql-2.2.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
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:
For new sessions on a test instance, add the library to the existing session preload list:
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:
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.