I went back and tried Erik's original test
(http://www.postgresql.org/message-id/dafad644f268ce1503e1b8b682aae38a.squirrel@webmail.xs4all.nl).
With a fresh checkout from master, the difference between the slow and
fast queries is much less dramatic than Erik reported. The reason is
that Alexander's GIN "fast scan" patch is very effective on that query.
Erik reported that the '^abcd' query took 140ms, vs 5ms for 'abcd'. On
my laptop, the numbers with a fresh checkout are about 2.5 ms vs. 1 ms,
and with fast scan disabled (by modifying the source code), 40ms vs 1ms.
So thanks to the fast scan patch, I don't think this patch is worth
pursuing anymore. Unless there are some other test case where this patch
helps, but the fast scan patch doesn't.
- Heikki