Re: Using Cursors in PHP

Lists: pgsql-php
From: Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>
To: pgsql-php(at)postgresql(dot)org
Subject: Using Cursors in PHP
Date: 2003-08-06 12:59:22
Message-ID: 200308061459.22825.a.schmitz@cityweb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php


Hello *,

I am just wondering if it is possible to use cursors within PHP. I need to
page query result from a big table and I am looking for a solution to avoid
scanning the complete table using limit and offset.

any ideas ?

best regards

-andreas


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>
Cc: <pgsql-php(at)postgresql(dot)org>
Subject: Re: Using Cursors in PHP
Date: 2003-08-06 15:51:21
Message-ID: Pine.LNX.4.33.0308060950030.15751-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

On Wed, 6 Aug 2003, Andreas Schmitz wrote:

>
> Hello *,
>
> I am just wondering if it is possible to use cursors within PHP. I need to
> page query result from a big table and I am looking for a solution to avoid
> scanning the complete table using limit and offset.

Yes, you can use cursors, no you can't expect them to survive from one
page to the next.

Luckily, Postgresql is smart enough to use indexes when you use offset
limit, but, of course, it must internally create the result set up to and
including the last row returned by the limit / offset.


From: Markus Bertheau <twanger(at)bluetwanger(dot)de>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>, pgsql-php(at)postgresql(dot)org
Subject: Re: Using Cursors in PHP
Date: 2003-08-08 08:01:40
Message-ID: 1060329700.4453.0.camel@severn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

В Срд, 06.08.2003, в 17:51, scott.marlowe пишет:
> On Wed, 6 Aug 2003, Andreas Schmitz wrote:
>
> >
> > Hello *,
> >
> > I am just wondering if it is possible to use cursors within PHP. I need to
> > page query result from a big table and I am looking for a solution to avoid
> > scanning the complete table using limit and offset.
>
> Yes, you can use cursors, no you can't expect them to survive from one
> page to the next.

What about the new feature in cursors "WITH HOLD"? Don't they survive?

--
Markus Bertheau <twanger(at)bluetwanger(dot)de>


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Markus Bertheau <twanger(at)bluetwanger(dot)de>
Cc: Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Using Cursors in PHP
Date: 2003-08-08 13:22:18
Message-ID: Pine.LNX.4.33.0308080721170.20444-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

On 8 Aug 2003, Markus Bertheau wrote:

> В Срд, 06.08.2003, в 17:51, scott.marlowe пишет:
> > On Wed, 6 Aug 2003, Andreas Schmitz wrote:
> >
> > >
> > > Hello *,
> > >
> > > I am just wondering if it is possible to use cursors within PHP. I need to
> > > page query result from a big table and I am looking for a solution to avoid
> > > scanning the complete table using limit and offset.
> >
> > Yes, you can use cursors, no you can't expect them to survive from one
> > page to the next.
>
> What about the new feature in cursors "WITH HOLD"? Don't they survive?

I don't think so. Basically, PHP is supposed to reset the connection if
it's persistant, and if it isn't persistant, then it's always a new
connection, which means a cursor shouldn't survive.

But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
that better may have a more definitive answer.


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: Markus Bertheau <twanger(at)bluetwanger(dot)de>, Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Using Cursors in PHP
Date: 2003-08-08 13:33:25
Message-ID: Pine.LNX.4.33.0308080733090.20552-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

On Fri, 8 Aug 2003, Rod Taylor wrote:

> > I don't think so. Basically, PHP is supposed to reset the connection if
> > it's persistant, and if it isn't persistant, then it's always a new
> > connection, which means a cursor shouldn't survive.
> >
> > But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
> > that better may have a more definitive answer.
>
> Yup.. This is where you setup a little Java to deal with persistent
> database elements like this and hook into it via PHP. It's a little
> nasty at the moment (though functional) but is supposedly greatly
> improved in PHP 5.
>
> http://ca2.php.net/manual/en/ref.java.php

Java providing connection pooling for PHP. Sweet!


From: Rod Taylor <rbt(at)rbt(dot)ca>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: Markus Bertheau <twanger(at)bluetwanger(dot)de>, Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>, pgsql-php(at)postgresql(dot)org
Subject: Re: Using Cursors in PHP
Date: 2003-08-08 13:42:11
Message-ID: 1060350130.97914.4.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

> I don't think so. Basically, PHP is supposed to reset the connection if
> it's persistant, and if it isn't persistant, then it's always a new
> connection, which means a cursor shouldn't survive.
>
> But I'm NOT familiar with "WITH HOLD" right now, so someone else who knows
> that better may have a more definitive answer.

Yup.. This is where you setup a little Java to deal with persistent
database elements like this and hook into it via PHP. It's a little
nasty at the moment (though functional) but is supposedly greatly
improved in PHP 5.

http://ca2.php.net/manual/en/ref.java.php


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: Markus Bertheau <twanger(at)bluetwanger(dot)de>, Andreas Schmitz <a(dot)schmitz(at)cityweb(dot)de>, pgsql-php(at)postgresql(dot)org
Subject: Re: Using Cursors in PHP
Date: 2003-08-08 17:34:43
Message-ID: 200308081734.h78HYhG02971@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-php

scott.marlowe wrote:
> On 8 Aug 2003, Markus Bertheau wrote:
>
> > ?? ??????, 06.08.2003, ?? 17:51, scott.marlowe ??????????:
> > > On Wed, 6 Aug 2003, Andreas Schmitz wrote:
> > >
> > > >
> > > > Hello *,
> > > >
> > > > I am just wondering if it is possible to use cursors within PHP. I need to
> > > > page query result from a big table and I am looking for a solution to avoid
> > > > scanning the complete table using limit and offset.
> > >
> > > Yes, you can use cursors, no you can't expect them to survive from one
> > > page to the next.
> >
> > What about the new feature in cursors "WITH HOLD"? Don't they survive?
>
> I don't think so. Basically, PHP is supposed to reset the connection if
> it's persistant, and if it isn't persistant, then it's always a new
> connection, which means a cursor shouldn't survive.

Actually, that brings up a problem --- our RESET ALL doesn't close
cursors that are kept open using WITH HOLD.

However, you are right that you can't be sure you will get the same
backend when you connect via a new page, so WITH HOLD doesn't help here.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073