Contents
Changelog
All notable changes to pg_num2int_direct_comp will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Unreleased
1.0.1 - 2026-11-30
Existing installations upgrade with ALTER EXTENSION pg_num2int_direct_comp UPDATE after installing the new files; no DROP EXTENSION is needed. There is no full 1.0.1 install script: CREATE EXTENSION runs the 1.0.0 script and then pg_num2int_direct_comp--1.0.0--1.0.1.sql.
Fixed
- A join chain linking two integer columns of different widths through a float column, such as
a.i2 = f.f8 AND f.f8 = b.i4, failed to plan withERROR: operator 532 is not a member of opfamily 1970(the operator and family numbers vary), under default settings, including inEXPLAIN. The three columns form one equivalence class whose btree families arefloat_opsandinteger_ops. The planner derivesa.i2 = b.i4and checks merge joins on it withfloat_ops, which had no entries comparing two different integer widths. 1.0.1 adds those 30 operators and 6 support functions (all core objects) tofloat_ops, and float4 × float8 (10 operators, 2 functions) tointeger_ops. Btreefloat_opsnow passesamvalidate();integer_opslacks only numeric × float, which the extension does not provide. Workaround on 1.0.0: cast one integer side to the float type, orSET enable_mergejoin = off. - Plan change in 1.0.1: a chain through two integer widths and a numeric column, such as
a.i2 = b.i4 AND b.i4 = n.n AND a.i2 = 5, still derivesb.i4 = 5but no longer derivesn.n = 5; the numeric side is probed with the join value instead. Results are unchanged, and stock PostgreSQL derives no such clause either. - The support-function switch is now registered as
pg_num2int_direct_comp.enable_support_functions, the name the README documents. 1.0.0 registered it aspg_num2int_direct_comp.enableSupportFunctions, so the documentedSET ... = offcreated a placeholder and had no effect. The library also reserves thepg_num2int_direct_compprefix, so a misspelled setting is now an error instead of a silent no-op. - Action needed if you set the camelCase name. There is no alias. A
pg_num2int_direct_comp.enableSupportFunctionsvalue persisted inpostgresql.confor withALTER DATABASE ... SET/ALTER ROLE ... SETis now an unknown name under the reserved prefix: when the library loads, PostgreSQL drops it with aWARNINGand the setting reverts to its default, so the optimization turns back on. Re-set it underpg_num2int_direct_comp.enable_support_functions(andRESETor remove the old name). - README:
<>is not in the btree operator families (btree has strategies 1-5 only); the GUC example’sEXPLAINoutput now matches what the server prints.
Changed
- The
DROP EXTENSIONcleanup trigger lists only the operator family entries whose operator or support function is a core object: 90 from 1.0.0 and the 48 that 1.0.1 adds. The 156 DROPs it no longer has targeted entries that PostgreSQL already removes whenDROP EXTENSIONdrops the extension’s own operators and functions (every int × float entry and every hash family entry). The 1.0.0 install script is trimmed in place; the 1.0.0 release on PGXN keeps the longer list, which removes the same entries.ALTER EXTENSION ... UPDATEreplaces it with the 1.0.1 list. - README: the numeric × float limitation now gives its actual reasons (how existing
numeric = float8comparisons resolve, and the cost of hashing), instead of saying exact comparison is infeasible. make check-versionaccepts an update script that ends at the default version in place of a full install script, and fails if an install or update script is missing fromDATA.
Tests
cross_width_chains(new): 3-way joins int × float × int for every integer pair and both float types (18 combinations), counted and withORDER BY ... LIMIT, at default settings and with merge joins forced, expecting no error; on 1.0.0 the 12 different-width combinations fail. It also recordsamvalidate()for the three btree families and the exact pairsinteger_opsstill lacks.float_int_ops,merge_joins: the whole-familypg_amopcounts are removed. They counted core PostgreSQL’s own entries too, so a PostgreSQL release changing those families would have broken them;extension_lifecycle’s footprint counts only what the extension adds.float_int_ops: the per-pair check now checks which operator holds each strategy (1:< 2:<= 3:= 4:>= 5:>), not only that strategies 1-5 exist, and a new check does the same for every btree entry infloat_ops,integer_opsandnumeric_ops. The MERGES check now starts from the expected int × float pairs, so a missing=is reported instead of passing.float_int_ops: transitivity tests now check stored float values at the float4 (224) and float8 (253) precision limits, where rounding comparisons would break transitivity, for int4 × float4, int8 × float8 and int8 × float4 (each reports how many nearby integers equal the stored value, expected at most 1); NaN and ±Infinity ordering is checked for all six float × int pairs in both operand orders; per-pair btree family completeness and MERGES checks list offenders instead of recording a count.extension_lifecycle: the GUC test now runs against the registered name (it recorded an error and identical plans before) and checks that a misspelled name is rejected; the post-DROP EXTENSIONcheck also covers the same-type entries added tofloat_opsandinteger_ops.comparison_exactness: Check 3 (operator functions, column vs column) now covers both operand orders, so thefloat OP intoperators are checked against the exact reference too; it reports how many cases it ran.ex_floatnow hasInfinityand-Infinityfor both float types. The hand-written NaN/Infinity checks infloat_int_ops(T018/T019) now point here.extension_lifecycle: the post-DROP EXTENSIONcheck no longer lists the entries it expects to be gone. It snapshotspg_amopandpg_amproc(all access methods and families) in a fresh database made fromtemplate0, installs the extension, prints what it added, and checks thatDROP EXTENSIONrestores the snapshot exactly, that a reinstall matches the first install, and that every upgrade path to the default version matches a fresh install (1.0.0 → 1.0.1; since 1.0.1 has no full install script, a fresh install takes the same path). The comparison also covers the extension’s member objects and the planner-relevant properties of its operators and functions.extension_lifecycle,doc_examples: the GUC blocksLOADthe library first, soSHOWand the misspelled-name check no longer depend on earlier statements in the file having used an operator.
1.0.0 - 2026-11-27
First tagged release, and the first on PGXN. A pre-release snapshot of the code was described here as 1.0.0 in January 2026 but never tagged; this entry replaces that description. If you built that snapshot from git, drop and recreate the extension: there is no upgrade script from it, and it had the wrong-result bugs listed under “Fixed in this release” below.
Added
- 108 operators:
=,<>,<,<=,>,>=for (numeric, float4, float8) × (int2, int4, int8), plus their commutators. Every comparison is exact: no value is rounded before it is compared. - Btree operator families: the operators join
integer_ops,numeric_opsandfloat_ops, with 9 cross-type comparison support functions, so indexes, indexed nested loop joins and merge joins apply to both int × numeric and int × float. See Float × Integer Btree Ops research. - Hash operator families: the equality operators are
HASHESand join thenumeric_opsandfloat_opshash families (integers are hashed as numeric or float8), so hash joins apply. - Constant predicate rewriting via
SupportRequestSimplify:- Impossible predicates:
int_col = 10.5::numeric→FALSE - Exact matches:
int_col = 100::numeric→int_col = 100(native operator) - Range boundaries:
int_col > 10.5→int_col >= 11 - Out-of-range constants:
int2_col = 99999→FALSEat plan time - The constant may be on either side, and NULL semantics are kept on nullable columns.
- Impossible predicates:
DROP EXTENSIONcleanup: an event trigger removes the extension’s entries from the built-in operator families, whichpg_dependcannot track, so the extension can be reinstalled cleanly.- Type aliases (
serial,bigserial,smallserial,decimal), SQL NULL handling, and IEEE 754 special values (NaN, Infinity). - PostgreSQL 16, 17, 18 and 19. 16 is the minimum: the NULL handling uses
Var.varnullingrels, which 16 added, and building against an older server stops with an#error. PostgreSQL 19 has alternate expected outputs for itsReplaces:EXPLAIN line. - Regression suite (pg_regress), including
comparison_exactness, which checks every int × numeric/float comparison against an exact reference, constant on either side, on NOT NULL and nullable columns, plus hash/equality consistency for every hashable operator.returning_old_newruns only on PostgreSQL 18 and later. - PGXN packaging:
META.json,make dist(writes the release zip from the committed tree) andmake check-version(checksMETA.jsonagainst the control file)..gitattributeskeeps the agent and editor files out of the archive. - CI: GitHub Actions builds with warnings as errors and runs the regression tests on PostgreSQL 16 to 19, on x86_64 and arm64.
-Werroris opt-in (make WERROR=1), so a compiler with warnings this code has not met still builds it.- Documentation: README,
doc/installation.md,doc/operator-reference.md,doc/benchmark.md,doc/development.md, and research notes underspecs/.
Performance
- Numeric values are compared by reading their digit arrays directly (
numeric_cmp_int64_direct()), withoutOidFunctionCalloverhead. - Hash functions compute on stack arrays, with no palloc/pfree.
- Integer type bounds are cached as Numeric values; operator OIDs are kept in a lazy per-backend array cache, checked against the catalog by tests.
Benchmark (2026-01-02):
| Operation | Extension | Stock PostgreSQL | Speedup |
|---|---|---|---|
| Point lookup | 0.025 ms (Index) | 17.3 ms (Seq Scan) | ~690x |
| Range scan | 0.8 ms (Bitmap) | 23.4 ms (Seq Scan) | ~29x |
| Nested Loop Join | 3 ms | 49,658 ms | ~16,500x |
Fixed in this release (relative to the January 2026 snapshot)
- Wrong results with the constant on the left of a range comparison:
const OP columnwas rewritten as if it werecolumn OP const, so<,<=,>and>=returned the complement of the right answer (for example0.5 > colmatched no rows forcol = 0).=and<>were not affected. - Wrong int × float results at the integer type limits: out-of-range floats were converted back to integers (undefined behaviour in C), and
(float) INT_MAXwas used as a range bound, which rounds up to 231 (float4) or 263 (float8).2147483647::int4 = 2147483648::float4returned true, and hash joins on such values used mismatched hashes. - Missing
MERGESon int2 × float4, int2 × float8 and int4 × float8=, so the planner never chose a merge join for them. - NULL semantics were dropped by some support-function rewrites.
- Build on PostgreSQL 16 and 17:
Var.varreturningtype, which exists only from 18, is now read only there. DROP EXTENSIONcleanup ran for any extension whose name started with ours, and ignored all errors; it now matches the whole name and ignores onlyundefined_object.
Removed (relative to the January 2026 snapshot)
- The
SupportRequestIndexConditioncallback, superseded bySupportRequestSimplify. doc/api-reference.mdanddoc/user-guide.md, merged intodoc/operator-reference.md.