pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedMove forward all (Was Re: How to get last 10 rows in a table on a large database?)
6+ messages / 2 participants
[nested] [flat]
* Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-07 10:25 Stoyan Genov <genov@digsys.bg>
0 siblings, 1 reply; 6+ messages in thread
From: Stoyan Genov @ 1999-11-07 10:25 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
> > 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?
Regards,
Stoyan Genov
^ permalink raw reply [nested|flat] 6+ messages in thread
* RE: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-08 00:32 Hiroshi Inoue <Inoue@tpf.co.jp>
parent: Stoyan Genov <genov@digsys.bg>
0 siblings, 1 reply; 6+ messages in thread
From: Hiroshi Inoue @ 1999-11-08 00:32 UTC (permalink / raw)
To: Stoyan Genov <genov@digsys.bg>; +Cc: pgsql-sql; Tom Lane <tgl@sss.pgh.pa.us>
> -----Original Message-----
> From: owner-pgsql-sql@postgreSQL.org [mailto:owner-pgsql-sql@postgreSQL.
> org]On Behalf Of Stoyan Genov
> Sent: Sunday, November 07, 1999 7:25 PM
> To: Tom Lane
> Cc: pgsql-sql@postgreSQL.org
> Subject: [SQL] Move forward all (Was Re: How to get last 10 rows in a
> table on a large database?)
>
>
> > > 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 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.
Regards.
Hiroshi Inoue
Inoue@tpf.co.jp
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-08 09:27 Stoyan Genov <genov@digsys.bg>
parent: Hiroshi Inoue <Inoue@tpf.co.jp>
0 siblings, 1 reply; 6+ messages in thread
From: Stoyan Genov @ 1999-11-08 09:27 UTC (permalink / raw)
To: Hiroshi Inoue <Inoue@tpf.co.jp>; +Cc: pgsql-sql
> > -----Original Message-----
> > From: owner-pgsql-sql@postgreSQL.org [mailto:owner-pgsql-sql@postgreSQL.
> > org]On Behalf Of Stoyan Genov
> > Sent: Sunday, November 07, 1999 7:25 PM
> > To: Tom Lane
> > Cc: pgsql-sql@postgreSQL.org
> > Subject: [SQL] Move forward all (Was Re: How to get last 10 rows in a
> > table on a large database?)
> >
> >
> > > > 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...
> Regards.
>
> Hiroshi Inoue
> Inoue@tpf.co.jp
Regards,
Stoyan Genov
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-09 00:26 Hiroshi Inoue <Inoue@tpf.co.jp>
parent: Stoyan Genov <genov@digsys.bg>
0 siblings, 1 reply; 6+ messages in thread
From: Hiroshi Inoue @ 1999-11-09 00:26 UTC (permalink / raw)
To: Stoyan Genov <genov@digsys.bg>; +Cc: 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@tpf.co.jp
Attachments:
backcsr.diff (text/plain, 809B) download
*** access/heap/heapam.c.orig Mon Aug 2 14:56:36 1999
--- access/heap/heapam.c Tue Nov 9 09:06:58 1999
***************
*** 833,842 ****
ReleaseBuffer(scan->rs_pbuf);
scan->rs_ptup.t_data = NULL;
scan->rs_pbuf = InvalidBuffer;
- if (BufferIsValid(scan->rs_nbuf))
- ReleaseBuffer(scan->rs_nbuf);
- scan->rs_ntup.t_data = NULL;
- scan->rs_nbuf = InvalidBuffer;
return NULL;
}
--- 833,838 ----
***************
*** 915,924 ****
ReleaseBuffer(scan->rs_nbuf);
scan->rs_ntup.t_data = NULL;
scan->rs_nbuf = InvalidBuffer;
- if (BufferIsValid(scan->rs_pbuf))
- ReleaseBuffer(scan->rs_pbuf);
- scan->rs_ptup.t_data = NULL;
- scan->rs_pbuf = InvalidBuffer;
HEAPDEBUG_6; /* heap_getnext returning EOS */
return NULL;
}
--- 911,916 ----
^ permalink raw reply [nested|flat] 6+ messages in thread
* RE: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-09 04:36 Hiroshi Inoue <Inoue@tpf.co.jp>
parent: Hiroshi Inoue <Inoue@tpf.co.jp>
0 siblings, 1 reply; 6+ messages in thread
From: Hiroshi Inoue @ 1999-11-09 04:36 UTC (permalink / raw)
To: Stoyan Genov <genov@digsys.bg>; +Cc: pgsql-sql
> >
> > > 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 ?
>
Sorry the patch is not right for 6.5.3 .
Please apply the following patch to 6.5.3 .
Regards.
Hiroshi Inoue
Inoue@tpf.co.jp
inline patch 1: access/heap/heapam.c (+0/-12 lines) download inline-1.patch
*** access/heap/heapam.c.orig Mon Aug 2 14:56:36 1999
--- access/heap/heapam.c Tue Nov 9 12:59:48 1999
***************
*** 775,782 ****
if (scan->rs_ptup.t_data == scan->rs_ctup.t_data &&
BufferIsInvalid(scan->rs_pbuf))
{
- if (BufferIsValid(scan->rs_nbuf))
- ReleaseBuffer(scan->rs_nbuf);
return NULL;
}
--- 775,780 ----
***************
*** 833,842 ****
ReleaseBuffer(scan->rs_pbuf);
scan->rs_ptup.t_data = NULL;
scan->rs_pbuf = InvalidBuffer;
- if (BufferIsValid(scan->rs_nbuf))
- ReleaseBuffer(scan->rs_nbuf);
- scan->rs_ntup.t_data = NULL;
- scan->rs_nbuf = InvalidBuffer;
return NULL;
}
--- 831,836 ----
***************
*** 855,862 ****
if (scan->rs_ctup.t_data == scan->rs_ntup.t_data &&
BufferIsInvalid(scan->rs_nbuf))
{
- if (BufferIsValid(scan->rs_pbuf))
- ReleaseBuffer(scan->rs_pbuf);
HEAPDEBUG_3; /* heap_getnext returns NULL at end */
return NULL;
}
--- 849,854 ----
***************
*** 915,924 ****
ReleaseBuffer(scan->rs_nbuf);
scan->rs_ntup.t_data = NULL;
scan->rs_nbuf = InvalidBuffer;
- if (BufferIsValid(scan->rs_pbuf))
- ReleaseBuffer(scan->rs_pbuf);
- scan->rs_ptup.t_data = NULL;
- scan->rs_pbuf = InvalidBuffer;
HEAPDEBUG_6; /* heap_getnext returning EOS */
return NULL;
}
--- 907,912 ----
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] Move forward all (Was Re: How to get last 10 rows in a table on a large database?)
@ 1999-11-09 11:15 Stoyan Genov <genov@digsys.bg>
parent: Hiroshi Inoue <Inoue@tpf.co.jp>
0 siblings, 0 replies; 6+ messages in thread
From: Stoyan Genov @ 1999-11-09 11:15 UTC (permalink / raw)
To: Hiroshi Inoue <Inoue@tpf.co.jp>; pgsql-sql
> > >
> > > > 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 ?
> >
>
> Sorry the patch is not right for 6.5.3 .
> Please apply the following patch to 6.5.3 .
>
> Regards.
>
> Hiroshi Inoue
> Inoue@tpf.co.jp
>
> *** access/heap/heapam.c.orig Mon Aug 2 14:56:36 1999
> --- access/heap/heapam.c Tue Nov 9 12:59:48 1999
> ***************
> *** 775,782 ****
> if (scan->rs_ptup.t_data == scan->rs_ctup.t_data &&
> BufferIsInvalid(scan->rs_pbuf))
> {
> - if (BufferIsValid(scan->rs_nbuf))
> - ReleaseBuffer(scan->rs_nbuf);
> return NULL;
> }
>
> --- 775,780 ----
> ***************
> *** 833,842 ****
> ReleaseBuffer(scan->rs_pbuf);
> scan->rs_ptup.t_data = NULL;
> scan->rs_pbuf = InvalidBuffer;
> - if (BufferIsValid(scan->rs_nbuf))
> - ReleaseBuffer(scan->rs_nbuf);
> - scan->rs_ntup.t_data = NULL;
> - scan->rs_nbuf = InvalidBuffer;
> return NULL;
> }
>
> --- 831,836 ----
> ***************
> *** 855,862 ****
> if (scan->rs_ctup.t_data == scan->rs_ntup.t_data &&
> BufferIsInvalid(scan->rs_nbuf))
> {
> - if (BufferIsValid(scan->rs_pbuf))
> - ReleaseBuffer(scan->rs_pbuf);
> HEAPDEBUG_3; /* heap_getnext returns NULL at end */
> return NULL;
> }
> --- 849,854 ----
> ***************
> *** 915,924 ****
> ReleaseBuffer(scan->rs_nbuf);
> scan->rs_ntup.t_data = NULL;
> scan->rs_nbuf = InvalidBuffer;
> - if (BufferIsValid(scan->rs_pbuf))
> - ReleaseBuffer(scan->rs_pbuf);
> - scan->rs_ptup.t_data = NULL;
> - scan->rs_pbuf = InvalidBuffer;
> HEAPDEBUG_6; /* heap_getnext returning EOS */
> return NULL;
> }
> --- 907,912 ----
>
>
>
> ************
>
I have applied the patch.
Now postgres 6.5.3 works fine (FETCH BACKWARD fetches
result after MOVE FORWARD ALL/FETCH FORWARD ALL).
Thank you very much.
Regards,
Stoyan Genov
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~1999-11-09 11:15 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-07 10:25 Move forward all (Was Re: How to get last 10 rows in a table on a large database?) Stoyan Genov <genov@digsys.bg>
1999-11-08 00:32 ` Hiroshi Inoue <Inoue@tpf.co.jp>
1999-11-08 09:27 ` Stoyan Genov <genov@digsys.bg>
1999-11-09 00:26 ` Hiroshi Inoue <Inoue@tpf.co.jp>
1999-11-09 04:36 ` Hiroshi Inoue <Inoue@tpf.co.jp>
1999-11-09 11:15 ` Stoyan Genov <genov@digsys.bg>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox