Re: select vs cursor/fetch speed disparity

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bosco Rama <postgres(at)boscorama(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: select vs cursor/fetch speed disparity
Date: 2011-10-08 05:46:09
Message-ID: 23997.1318052769@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bosco Rama <postgres(at)boscorama(dot)com> writes:
> I have a strange disparity between a query that is run as a
> straight select and the same query via a cursor. I hope I can
> jog someone's memory with the description as I have been unable
> to create a sanitized and/or reduced data set & schema that will
> reproduce this ... so far. :-(

Cursors are biased towards fast-start plans on the theory that you
may not be intending to fetch the whole result. Queries with ORDER BY
and/or LIMIT are particularly likely to see plan changes as a
consequence of that. In 8.4 and up you can frob the
cursor_tuple_fraction setting to adjust this preference. Use
"EXPLAIN query" vs "EXPLAIN DECLARE CURSOR FOR query" to see what
sort of plan you're getting.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-10-08 06:01:58 Re: Installation woes via Macports on Mac OS X 10.7
Previous Message René Fournier 2011-10-08 02:35:51 Re: Getting PostGIS 1.5.3 working with Postgresql90 (Macports)