Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 463F847708B for ; Wed, 8 Jan 2003 18:05:24 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 5D0A84764D6 for ; Wed, 8 Jan 2003 18:05:13 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h08N5B0U022683; Wed, 8 Jan 2003 18:05:11 -0500 (EST) To: Hiroshi Inoue Cc: Bruce Momjian , pgsql-hackers@postgresql.org Subject: Re: MOVE LAST: why? In-reply-to: <22435.1042065746@sss.pgh.pa.us> References: <200301072329.h07NT2X28922@candle.pha.pa.us> <27934.1041984327@sss.pgh.pa.us> <3E1B9DCD.75859501@tpf.co.jp> <501.1041997832@sss.pgh.pa.us> <3E1BA5E6.9463718F@tpf.co.jp> <863.1042000401@sss.pgh.pa.us> <3E1BAFF6.B0114A67@tpf.co.jp> <1082.1042002375@sss.pgh.pa.us> <3E1BEFFE.88B57516@tpf.co.jp> <22435.1042065746@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 08 Jan 2003 17:42:26 -0500" Date: Wed, 08 Jan 2003 18:05:11 -0500 Message-ID: <22682.1042067111@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/413 X-Sequence-Number: 34023 I said: > Yeah, backwards scan is not implemented for quite a large number of plan > node types :-(. I am not sure that it is practical to fix them all. > I have been toying with the notion of making cursors on complex plans > safe for FETCH BACKWARD by sticking a MATERIAL node atop the plan, if > the top plan node isn't one that can handle backwards scan. I forgot to mention plan B: make use of ReScan. This could work like so: 1. Cursor keeps track of row number (number of rows it's fetched). 2. To scan backwards when top plan type doesn't handle it, rewind all the way with ReScan, then move forward the appropriate number of rows. This would avoid any added overhead in the case where a backwards move is never requested, and it also would support MOVE BACKWARD ALL quite efficiently (much more so than now). On the other hand, it'd really suck if the user asks for backwards scan from a point far into the output. Perhaps we could do something with a hybrid technique: don't materialize the cursor output unless user actually asks for backwards scan. If he does, then create a tuplestore and put the data into it (rescanning the query output to do so), and finally supply the tuples from the tuplestore. regards, tom lane