GiST intrapage-indexing (skip tuples) -- A/B benchmark results ============================================================== Patch: v3 "Add intrapage indexing to GiST", CF 7200. base = 11591f273e6 (parent of the patch) gist = e9689a3f633 (the patch) Both built from the same tree, same configure; difference is the one commit. Harness: bench/gist_intrapage_bench.sh (self-contained; see that file / README). Machine: Apple M-series, macOS 15; shared_buffers=2GB, maintenance_work_mem=1GB, autovacuum=off, jit=off, fsync=off. Scans: pgbench 1 client, 3s warm + 10s measured, latency-average (ms, lower is better). Each row below is PATCHED-vs-BASE. "x" on build/size = test/base (>1 = worse); "x" on lat = test/base (<1 = patch faster). Numbers reproduced across two independent passes (BUILD_REPEATS=3 and =1); both are shown where they differ. rows = 5,000,000 (cube: 2,000,000) build (s) index size scan lat (ms) patched dataset / query base gist x base gist x base gist x leaf/int/skip ---------------------------------------------------------------------------------------------------- point selective-box 22.2 29.2 1.3x 473 MB 473 MB 1.00 0.536 0.498 0.93 60010/546/6368 mrange selective-overlap 53.3 47* ~1x 240 MB 241 MB 1.00 0.100 0.085 0.85 30534/258/2090 temporal pk-probe (id=) 2.7 2.8 1.0x 318 MB 320 MB 1.01 0.036 0.032 0.90 40540/441/3552 temporal id-band (same temporal index) 0.073 0.069 0.95 40540/441/3552 tsrange selective-window 2.5 2.5 1.0x 174 MB 174 MB 1.00 0.102 0.098 0.96 22124/197/1568 cube selective-overlap 16.2 254.6 15.8x 232 MB 490 MB 2.11 0.031 0.032 1.03 49117/13619/38215 * mrange build at BUILD_REPEATS=1 measured faster on gist; that is single-shot noise (the patch cannot speed up a build). At BUILD_REPEATS=3 it is ~neutral. point's +30% build cost, by contrast, reproduced in both passes -- it is real. datasets point : box over a 10000x10000 grid; ~0.01% box-containment probe (control: cheap consistent, tiny key). mrange : int4multirange, one small range each; selective && overlap probe. temporal : (id int, valid_at tstzrange), btree_gist + range_ops, ~10 periods per id, generated in id order (clustered) -- the WITHOUT OVERLAPS case. q1 = temporal PK probe (id = const AND valid_at @> instant); q2 = small id band (id BETWEEN x AND x+50). tsrange : append-only time series, single tstzrange in time order; selective && window probe. cube : 2,000,000 uniform-random 4-D point-cubes; selective && overlap probe (large union keys, poor pruning -- the adversarial case). What it shows ------------- 1. THERE IS A REAL, REPRODUCIBLE READ WIN on common, well-clustered opclasses: ~15% (mrange), ~7-10% (point, temporal PK), ~4-5% (temporal id-band, tsrange). Every one of the 7 non-cube queries got faster, across two independent passes -- consistent direction, so this is signal, not noise. The temporal (int, tstzrange) case -- the single most common GiST use -- benefits (~5-10%) at +0.5% size and neutral build. That is the headline positive result. The win is MODEST (single digits to ~15%), as expected: skip tuples prune `consistent` calls only on INTERNAL pages, which are <2% of the index; the dominant leaf-level `consistent` cost is untouched (leaf-only exclusion). It grows with tree depth (invisible at 1M rows, measurable at 5M). 2. IT IS NOT FREE. CREATE INDEX regressed ~30% on point (reproduced), and skip tuples roughly DOUBLE the internal-page count on every dataset (point 515->546 is mild; temporal 223->441, tsrange 99->197). Because internal pages are a small fraction of the index, total size barely moves (<=0.5%) for these opclasses -- but see cube. 3. IT IS NOT SELF-LIMITING. On cube (large union keys + poorly-clustered data) the internal-page doubling compounds a GiST that already has low fanout: 30x more internal pages, fanout ~65 -> ~3.6, index size 2.1x, build 15.8x, and ZERO read benefit (random high-dim unions overlap the query, so no group is ever rejected). This is a build/split pathology, not mere write amplification: a 1-skip-per-16-downlinks overhead cannot produce a 30x internal blowup. Takeaway for the thread ----------------------- The feature earns its keep on ranges/multiranges/points/temporal -- a small but real read speedup at small cost -- so the direction is worthwhile. But it needs a GUARD so it cannot fire on the cube-like cases: don't form a group whose union is barely more selective than its members, and/or make skip-tuple formation opt-in per opclass or per index (reloption). The patch should also (a) justify GIST_SKIP_GROUP_SIZE=16 and the split behaviour that lets internal fanout fall to ~3.6 on cube, and (b) report the CREATE INDEX cost (point +30%). Reproduce --------- # from a postgres checkout on the patch branch: CONFIGURE_FLAGS="--enable-tap-tests" \ bench/gist_intrapage_bench.sh build . HEAD~1 HEAD # or, if you already have two installs: bench/gist_intrapage_bench.sh run /path/base/bin /path/test/bin 5000000 10 # knobs: ROWS (4th arg), SCAN_SECS (5th), BUILD_REPEATS, DATASETS env. Incremental INSERT: time + WAL (bench/insert_wal_ab.sh) -------------------------------------------------------- Checking a second reviewer's claims ("500k INSERT ~1.4x faster" and "~5% more WAL"). Preload 5,000,000 random points + GiST index, one warmup batch + CHECKPOINT, then 6 measured 500k-row INSERT batches. gist run FIRST (so a "faster" result cannot be a run-order cold-cache artifact). Steady state (reps 2-6; rep1 carries post-checkpoint full-page images for both and is excluded). point opclass, fsync=off, shared_buffers=2GB. insert time WAL per 500k batch base ~2.47 s ~112 MB gist ~2.03 s ~125 MB ratio gist 1.22x FASTER gist +12% WAL Both directions reproduce our own measurement: * INSERT is genuinely faster (~1.22x here; reviewer said ~1.4x). Real mechanism: the insert DESCENT prunes whole groups when choosing a subtree, so it makes fewer `penalty` calls per internal page. Under fsync=off with the index in shared buffers the insert is CPU-bound, so fewer comparisons -> lower wall time. (I was initially wrong to call a faster insert impossible.) * INSERT emits MORE WAL (~+12% steady-state here; reviewer said ~5%; including full-page images the single-batch figure was +3.7% -- FPIs dilute the %, so ~5% is plausible under their settings). Mechanism: full-page logging of the extra internal-page skip-tuple maintenance. * The two are NOT contradictory: faster wall-clock (fewer CPU comparisons) and more WAL bytes (more page maintenance) coexist under in-memory / fsync=off. NOTE the build-vs-insert split: bulk CREATE INDEX is SLOWER with the patch (point ~+30%, cube 15.8x -- it forms skip groups via the split machinery, pure added work with no descent savings), while incremental single-row INSERT is FASTER (fewer penalty calls on descent). Different code paths, opposite signs. The reviewer's third claim -- "sorted-tree joins 1.6-1.9x faster" -- is NOT credible for this patch and was not reproduced: GiST produces no sorted output (no amcanorder pathkeys, overlapping subtrees), so there is no sorted/merge-join or Sort-elimination path for it to speed up, and the patch touches only internal pages. If it means a nested-loop spatial/temporal join with an inner GiST probe, the per-probe read win measured above (<=~15%) cannot yield 1.6-1.9x. Ask for the exact query + EXPLAIN (ANALYZE); this figure likely reflects something other than the patch (a plan change, caching, or a mis-attributed measurement).