Key duration starts so summaries stay fast beyond float8's range
- github
- github/openchronology/timeline-app
- commit
- main
- github/athanclark
PostgreSQL duration summaries range-scan an index on each start's float8 approximation and recheck exact mpq values. Results were always correct, but float8 saturates: every start beyond ±1.8e308 (or below ~1e-308) shared one key (±Infinity or 0), so each summary group read all of them. With 20,000 such durations a view took 5-7 s instead of ~100 ms, and the cost grows with durations times groups, toward the 30 s statement timeout. The index key is now oc_qkey: ±((2^40 + decimal exponent)·10^30 + first 30 significant digits) as one numeric. Truncation keeps it monotone, the exponent never saturates, and the extra digits also separate starts that float8 could not (nanoseconds on epoch seconds). Starts agreeing in 30 significant digits still share a key; the exact recheck keeps them correct. The equivalence test adds a key-order oracle (powers of ten, their neighbours, ±1e10000, fractions) and starts spread far beyond float8. Closes #54 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/openchronology/timeline-app/commit/b91355d8d1822f020a866499b776cd738b5e93e7
Related
Open Key duration starts so summaries stay fast beyond float8's range in the timeline