Re: Showing progress of a database function

Поиск
Список
Период
Сортировка
От Albert Cervera Areny
Тема Re: Showing progress of a database function
Дата
Msg-id 200503020822.51327.albert@sedifa.com
обсуждение исходный текст
Ответ на Showing progress of a database function  ("Tambet Matiisen" <t.matiisen@aprote.ee>)
Список pgsql-interfaces
Would it be a solution for your problem to use LIMIT and OFFSET and make X
iterations?

A Dimarts 01 Març 2005 14:55, Tambet Matiisen va escriure:
> Hi everybody!
>
> When designing database-centric applications it is always good idea to
> push as much logic as possible to server side. The logic can be
> implemented as check constraints, triggers and functions. The problem
> is, that for lengthy function calls it will be impossible to see the
> progress and to cancel the operation, unless your client library
> supports asynchronous queries. Qt for example doesn't, like many others.
>
> My idea was to use cursor as progress indicator for the function.
> Simplified example:
>
> create or replace function process_big_table() returns refcursor
> language plpgsql as
> declare
>   cur as refcursor;
> begin;
>   open cur for
>     select process_row(id)
>     from big_table
>     where special_condition
>     order by special_order;
>   return cur;
> end;
>
> As you see, there is another function process_row(), which does the
> actual processing. This function has to be called for certain rows in
> big table, in certain order. In client code I do something like this:
>
> begin;
> select process_big_table(); -- returns the name of the cursor
> loop
>    fetch next from <cursor name>;
>    <update progress counter>
>    <if cancel was pressed do rollback and break>
> end loop
> commit;
>
> I expected it to call process_row() every time I fetch a row. But
> actually it processes all of them on first fetch and all following rows
> are returned in constant time. Is this a normal way of operation? Or
> does it depend on query? Are the query results always precalculated at
> the server side and the save from using cursors is just not to download
> all rows to client?
>
> If anyone has other ideas how to show progress of a database function,
> then you are welcome to share. I have considered using notice
> processing, but this requires access to libpq objects such as PGconn,
> which can be tricky with Qt (altough possible, as Qt uses libpq
> internally). And to be able to cancel requests I still need asynchronous
> query API, which is missing in Qt.
>
>   Tambet
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

--
Albert Cervera Areny
Dept. Informàtica Sedifa, S.L.

Av. Can Bordoll, 149
08202 - Sabadell (Barcelona)
Tel. 93 715 51 11
Fax. 93 715 51 12

====================================================================
........................  AVISO LEGAL  ............................
La   presente  comunicación  y sus anexos tiene como destinatario la
persona a  la  que  va  dirigida, por  lo  que  si  usted lo  recibe
por error  debe  notificarlo  al  remitente  y   eliminarlo   de  su
sistema,  no  pudiendo  utilizarlo,  total  o   parcialmente,   para
ningún  fin.  Su  contenido  puede  tener información confidencial o
protegida legalmente   y   únicamente   expresa  la  opinión     del
remitente.  El   uso   del   correo   electrónico   vía Internet  no
permite   asegurar    ni  la   confidencialidad   de   los  mensajes
ni    su    correcta     recepción.   En    el  caso   de   que   el
destinatario no consintiera la utilización  del correo  electrónico,
deberá ponerlo en nuestro conocimiento inmediatamente.
====================================================================
........................... DISCLAIMER .............................
This message and its  attachments are  intended  exclusively for the
named addressee. If you  receive  this  message  in   error,  please
immediately delete it from  your  system  and notify the sender. You
may  not  use  this message  or  any  part  of it  for any  purpose.
The   message   may  contain  information  that  is  confidential or
protected  by  law,  and  any  opinions  expressed  are those of the
individual    sender.  Internet  e-mail   guarantees   neither   the
confidentiality   nor  the  proper  receipt  of  the  message  sent.
If  the  addressee  of  this  message  does  not  consent to the use
of   internet    e-mail,    please    inform     us    inmmediately.
====================================================================




В списке pgsql-interfaces по дате отправления:

Предыдущее
От: "Tambet Matiisen"
Дата:
Сообщение: Showing progress of a database function
Следующее
От: "Tambet Matiisen"
Дата:
Сообщение: Re: Showing progress of a database function - solution for Qt