Re: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)

From: Hiroshi Inoue <Inoue(at)tpf(dot)co(dot)jp>
To: Stoyan Genov <genov(at)digsys(dot)bg>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
Date: 1999-11-09 00:26:20
Message-ID: 38276A2C.F1ECB937@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Stoyan Genov wrote:

> > > > > You are unable to say:
> > > > > begin transaction;
> > > > > declare tbl_cur cursor for .... .....
> > > > > move forward all in tbl_cur;
> > > > > fetch backward 10 in tbl_cur;
> > > > > ...........
> > > > > end transaction;
> > > > > because when you "move forward all" the result gets lost.
> > > >
> > > > Huh? It seems to work fine for me.
> > >
> > > Well, it does not seem to work for me neither on the 6.4.2 nor on the
> > > 6.5.(1|2)
> > > version. I'll try 6.5.3 as well...
> > > Any ideas why this is so?
> > >
> >
> > Doesn't your query have any qualification(WHERE clause) about
> > columns in index ?
> > If there's no qualification,PostgreSQL optimizer chooses sequential
> > scan(however current developing tree probably chooses Index scan
> > in case of ORDER BY).
> > In case of Index scan,"fetch backward .." after "move forward all" is
> > possible after 6.5 ,
> > But in case of sequential scan,maybe it's still impossible.
>
> I have tested this - for a sequental scan it is still impossible (talking
> 6.4.2 and 6.5.* versions)
>
> > I knew the way to fix it but am not sure now.
> > Do you really want to make it possible ?
> > It isn't an appropriate way to get last rows because "move forward
> > all" takes very long time.
> >
>
> Of course it is not an appropriate way to get the last rows like this.
> The "right" way IMHO is to reverse the order in the query and to get the
> first
> rows.
>
> It is just for the sake of truth...
>

OK Attached is a patch.
Could you apply to 6.5.3 ?

Regards.

Hiroshi Inoue
Inoue(at)tpf(dot)co(dot)jp

Attachment Content-Type Size
backcsr.diff text/plain 811 bytes

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hiroshi Inoue 1999-11-09 04:36:26 RE: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
Previous Message Moray McConnachie 1999-11-08 22:42:30 Re: [SQL] parser :parse error