X-Original-To: pgsql-hackers@postgresql.org Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id ED506475F1C; Sun, 9 Mar 2003 16:00:58 -0500 (EST) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2889743; Sun, 09 Mar 2003 13:00:45 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Tom Lane , pgsql-hackers@postgreSQL.org, pgsql-sql@postgreSQL.org Subject: Re: [SQL] Cursors and backwards scans and SCROLL Date: Sun, 9 Mar 2003 12:59:35 -0800 User-Agent: KMail/1.4.3 References: <21621.1047242111@sss.pgh.pa.us> In-Reply-To: <21621.1047242111@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200303091259.35423.josh@agliodbs.com> X-Archive-Number: 200303/320 X-Sequence-Number: 36566 Tom, > Postgres' implementation of cursors has always had a problem with doing > MOVE or FETCH backwards on complex queries. Coincidnetally enough, I was just chatting with one of my contractors yesterday about how the one thing that Transact-SQL has to offer is a really good cursor implementation. It would be lovely to improve ours to match. > Fixing this directly seems unreasonably difficult, so I'm currently > working on fixing it by inserting a Materialize plan node at the top of > the plan tree for a cursor, if the plan tree couldn't otherwise support > backwards scan. The Materialize node will save aside a copy of each row > as it's fetched from the underlying plan, and use this copied table if > any backwards scanning is asked for. Sounds good to me. It's also very similar to what T-SQL does for a STATIC or KEYSET cursor, and works very well in their implementation. (FWIW, T-SQL's cursor types, such as DYNAMIC and KEYSET, are unnecessary for Postgres due to MVCC) > 2. Error out only if a backwards fetch is actually attempted on a plan > tree that can't handle it (which could only happen if SCROLL wasn't > I'm presently leaning to #2, even though it exposes implementation > details. I'm open to discussion though. Any preferences? Other ideas? This sounds like a good idea to me in a staggered-implementation sense if it's doable. That is, we'd implement the behavior in #2 in the next version of Postgresql, and the behavior in #1 or in #3 in the version after that. If, however, the implementation of #2 is too difficult, then I think #3 would be a good choice.