Peter Geoghegan <p...@bowt.ie> writes: > We could get rid of dynamic allocations for BTStackData in > _bt_first(), perhaps. The problem is that there is no simple, > reasonable proof of the maximum height on a B-tree, even though a > B-Tree with more than 7 or 8 levels seems extraordinarily unlikely.
Start with a few entries preallocated, and switch to dynamically allocated space if there turn out to be more levels than that, perhaps? Not sure if it's worth the trouble. In any case, what I was on about is _bt_preprocess_keys() and adjacent code. I'm surprised that those aren't more expensive than one palloc in _bt_first. Maybe that logic falls through very quickly in simple cases, though. regards, tom lane