Обсуждение: Update 3 columns w/ 1 function calc 3 values?

Поиск
Список
Период
Сортировка

Update 3 columns w/ 1 function calc 3 values?

От
paallen@attglobal.net
Дата:
Hi all,

I am moving some of my old MS Access functions to
plpgsql.

My function was made to return coordinates, X,Y,Z
for a point along a curved line.  So it is not the
fastest of functions because it has to call and
query data from 3 different tables.  I used to
just create 3 wrapper functions for my main
function which would return the x, y, and z values
seperately but that requires the main function to
be called 3 seperate times.  So here is my bottle
neck.  Of course I need to update +50,000 records.

What should I do to speed this up.  What is the
best way to update 3 columns from one function
call.  In MSACCESS I once rig the function to
cycle through the records with a curser but that
was slow and would crap out due to the shear number.

Thanks,

Phil 



Re: Update 3 columns w/ 1 function calc 3 values?

От
"William Leite Araújo"
Дата:
2006/10/3, paallen@attglobal.net <paallen@attglobal.net>:
Hi all,

I am moving some of my old MS Access functions to
plpgsql.

My function was made to return coordinates, X,Y,Z
for a point along a curved line.  So it is not the
fastest of functions because it has to call and
query data from 3 different tables.  I used to
just create 3 wrapper functions for my main
function which would return the x, y, and z values
seperately but that requires the main function to
be called 3 seperate times.  So here is my bottle
neck.  Of course I need to update +50,000 records.

What should I do to speed this up.  What is the
best way to update 3 columns from one function
call.  

     It's realy very hard say something without the involving tables schema.
     You can:
        - change the function to return x,y,z in one call only ?
        - join the tables?
        - what is the function language?
 

In MSACCESS I once rig the function to
cycle through the records with a curser but that
was slow and would crap out due to the shear number.

Thanks,

Phil



--
William Leite Araújo

Re: Update 3 columns w/ 1 function calc 3 values?

От
Bruno Wolff III
Дата:
On Tue, Oct 03, 2006 at 14:55:55 +0000, paallen@attglobal.net wrote:
> My function was made to return coordinates, X,Y,Z
> for a point along a curved line.  So it is not the
> fastest of functions because it has to call and
> query data from 3 different tables.  I used to
> 
> What should I do to speed this up.  What is the
> best way to update 3 columns from one function
> call.  In MSACCESS I once rig the function to
> cycle through the records with a curser but that
> was slow and would crap out due to the shear number.

Why is the data in three different tables? It is unusual to not have all
coordinates in the same table using one column per coordinate.

If you need to update 3 tables, you will need 3 update statements.
Doing all of the updates in a single transaction will help.
If possible doing all of the updates for each coordinate table in one command
will help. To do that you would need the data to be coming from data already
in the database.
Chnaging the design of your database so that the coordinates are all in the
same table (assuming that is possible) would be a good idea.


Re: Update 3 columns w/ 1 function calc 3 values?

От
Markus Schaber
Дата:
Hi, paallen,

paallen@attglobal.net wrote:

> I am moving some of my old MS Access functions to
> plpgsql.
> 
> My function was made to return coordinates, X,Y,Z
> for a point along a curved line. 

Depending on the actual kind of data, you might want to look into the
PostgeSQL geometry types, or PostGIS for your geometric data.

> What should I do to speed this up.  What is the
> best way to update 3 columns from one function
> call.  In MSACCESS I once rig the function to
> cycle through the records with a curser but that
> was slow and would crap out due to the shear number.

It might work to mark the function as "stable", and have it return a
compound type in a subselect with an "AS foo" aliasname. Then you should
be able to address the compound's elements via foo.x, foo.y and foo.z.

Or use PostGIS, it's capable of processing 3D points.

HTH,
Markus

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org