Revised patch with reordering in GiST is attached (knn-gist-recheck-in-gist.patch) as well as testing script (test.py).
I meant to do a bit of testing on this (assuming it's still needed), but the patches need rebasing - Heikki fixed a few issues, so they don't apply cleanly.
Both patches are revised.
Both patches are rebased against current master.
This looks pretty much ready. I'm going to spend some time on this on Friday, and if all looks good, commit. (Thursday's a public holiday here).
Very good, thanks!
One quick comment:
It would be good to avoid the extra comparisons of the distances, when the index doesn't return any lossy items. As the patch stands, it adds one extra copyDistances() call and a cmp_distances() call for each tuple (in a knn-search), even if there are no lossy tuples.