It seems trivial to accelerate a MAX or MIN query with a BRIN index. You just find the page range with the largest/smallest value, and then only scan that one. Would that be hard to implement? I'm interested in working on it if someone can give me some pointers. Somewhat harder but still possible would be using BRIN indexes to accelerate ORDER BY. This would require a sorting algorithm that can take advantage of mostly-sorted inputs. You would sort the page ranges by their minimum or maximum value, then feed the sorting algorithm in that order.
> Yeah. I would urgently recommend that people *not* try to build new > things like planagg.c right now. A large part of the point of upper > planner path-ification is to have a less grotty way of dealing with > things like specialized aggregate implementations. Ok. I will wait and ask again later.
This a great solution to this problem, one I've found to be very common in web development. The technique will work to add RI to Django's generic foreign keys, which are implemented with an id column and a type-flag column. : https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations