From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
---|---|
To: | Eric Ridge <ebr(at)tcdi(dot)com> |
Cc: | Pgsql-General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Cursors and Transactions, why? |
Date: | 2004-04-06 15:54:35 |
Message-ID: | 4072D2BB.3040403@Yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Eric Ridge wrote:
> Why must a cursor be defined in an open transaction? Obviously there's
> a good reason, but I can't figure it out. On a high level, what would
> be involved in allowing a cursor to outlive the transaction that
> created it?
Because the transaction is what protects the rows that build the result
set from being removed by vacuum. In PostgreSQL, a cursor is a running
query executor just sitting in the middle of its operation. If the
underlying query is for example a simple sequential scan, then the
result set is not materialized but every future fetch operation will
read directly from the base table. This would obviously get screwed up
if vacuum would think nobody needs those rows any more.
>
> Cursors seem as if they have some nice performance benefits (esp. if
> you're not using all rows found), but their usefulness drops
> considerably since you must leave a transaction open.
And now you know why they are so good if you don't use all rows. This
benefit I think goes away if you use Joe Conway's suggestion of WITH HOLD.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin M. Roy | 2004-04-06 16:40:12 | Re: Storing jpgs |
Previous Message | David Wheeler | 2004-04-06 15:43:49 | Re: pg_autovacuum won't make on FreeBSD |