# PostgreSQL hash equality rechecks

A controlled clean-data software observation, not a storage benchmark or
corruption experiment. Three fresh PostgreSQL 16.15 clusters on one host produced
the published run-1.json, run-2.json and run-3.json captures.

## Reproduce
Run as an unprivileged user with PostgreSQL server and client binaries installed:

```sh
python3 -B observe.py --output replay.json
python3 -B -m unittest discover -s . -p test_observe.py
python3 -B -O -m unittest discover -s . -p test_observe.py
```

Use --bindir and --client-bin for separate server/client installations.
The script accepts no existing database URL or data directory. It creates a
private temporary cluster, uses a local Unix socket with no TCP listener, and
stops the server in a finally block before removing that temporary directory.
Output creation is exclusive: an existing capture is not overwritten.

## Method
Search decimal text representations of integers 1 through 250000 with PostgreSQL
hashtext. Group equal hashes, order groups by their smallest integer, and select
the first pair. This intentionally selects a collision; it estimates no natural
collision probability. On the recorded build, 15601 and 180514 share the signed
32-bit hash -1082004559. The pair is not promised stable across versions.

Create a two-row C-collated text table and one hash index. For equality with
15601, discourage competing paths to observe an Index Scan, Bitmap Heap Scan
and sequential control. Assert actual plan type, index identity, one execution,
one returned row and recheck counters. Run each SELECT separately from EXPLAIN
ANALYZE, which discards result rows. Verify the whole two-row table before and
after; no mutation, corruption, TOAST value or concurrent client is introduced.

The bitmap returns two candidates; its one exact heap block and zero lossy
blocks coexist with one row removed by index recheck. The ordinary index scan
also rejects one candidate; the sequential control rejects one row by its filter.
These are execution counters, not page-integrity checks, physical disk reads,
latency measurements or a speed comparison. Repeated captures check repeatability,
not independent sampling or statistical uncertainty.

Each capture retains SQL, plans, query output, executable hashes and probe hash.
Offline tests bind the plans to the SQL transcript and reject altered rows,
hashes, plan types, loop counts, rechecks and bitmap precision. These checks
establish internal consistency, not cryptographic proof of execution.
The recorded PostgreSQL 16.15 behavior and PostgreSQL 18 documentary discussion
are separate evidence; this is not a replication of Litwin's 1980 evaluation.

## Primary sources
- PostgreSQL 16 hash indexes: https://www.postgresql.org/docs/16/hash-index.html
- PostgreSQL 16 EXPLAIN: https://www.postgresql.org/docs/16/using-explain.html
- PostgreSQL REL_18_0 hash scan implementation:
  https://github.com/postgres/postgres/blob/REL_18_0/src/backend/access/hash/hash.c
- Litwin, W. (1980), Linear Hashing: A New Tool for File and Table Addressing,
  VLDB, pp. 212-223; reviewed sections 2.1 and 3, not used as a modern speed claim.
  https://hackthology.com/pdfs/Litwin-1980-Linear_Hashing.pdf

Accessed 2026-11-18. External source code/papers remain under their own licenses;
they are linked, not redistributed.
