From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: about cursors |
Date: | 2007-06-16 21:49:53 |
Message-ID: | 20070616214953.GA6672@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, Jun 16, 2007 at 09:58:27AM -0700, Ottavio Campana wrote:
> At this point I'm not able to understand any more if cursor are useful
> to reduce computational needs compared to running the same query each
> time with limit and offset.
A cursor is generally much cheaper because you only execute the query
once. You only have parse/plan/initialise/execute the query once. For
expensive queries this can be a huge saving. If you have a table with
10 million records, a cursor will only go through the table once.
> One last question: what happens to unclosed cursors? I mean, suppose an
> application opens a cursor and crashes. What happens to that cursor? Is
> there a way to close idle cursors?
Cursors are attached to the transactio and session, if either ends, the
cursor dies with it...
Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Staubo | 2007-06-16 22:05:29 | Re: What O/S or hardware feature would be useful for databases? |
Previous Message | Erick Papadakis | 2007-06-16 21:39:32 | Re: PHP sucks!! - was: persistent db connections in PHP |