Oliver Jowett <oliver@opencloud.com> writes:
> Tom Duffey wrote:
>> This makes a huge difference, thanks. However, is there anything I can
>> do to help improve the performance of that query when using a newer
>> protocol?
> We need to work out what is going wrong under the newer protocol first,
It looks pretty obvious from the peanut gallery: in the parameterized
query, the planner daren't choose an indexscan, because for the vast
majority of the possible values of the parameter an indexscan would
suck.
Tom's apparently only interested in the case where the parameter is
close to the end of the range, so that only a few rows need to be
retrieved. In this case the indexscan wins big, but the planner can't
count on that.
A possible hack is to put a reasonably small LIMIT on the query.
regards, tom lane