Обсуждение: Performance of update

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

Performance of update

От
sam
Дата:
Hi
Iam trying to update a database table with approx 45000 rows. Iam not
updating all rows at a time. Iam updating 60 rows at a given time for
example. and this is happening in a FOR LOOP. A function that has the
update statements is called within the loop.

The updates take too long.....is postgres slow in doing updates on
large tables or is it because of the function call within the loop???

Thanks
Sam

Re: Performance of update

От
Tommy Gildseth
Дата:
sam wrote:
> Hi
> Iam trying to update a database table with approx 45000 rows. Iam not
> updating all rows at a time. Iam updating 60 rows at a given time for
> example. and this is happening in a FOR LOOP. A function that has the
> update statements is called within the loop.
>
> The updates take too long.....is postgres slow in doing updates on
> large tables or is it because of the function call within the loop???


45000 rows isn't a large table, and there's no reason why it should be
slow in updating 60 rows.
Did you VACUUM ANALYZE; your table recently? Are the columns you use in
your WHERE indexed?
What does EXPLAIN ANALYZE say?


--
Tommy Gildseth

Re: Performance of update

От
Volkan YAZICI
Дата:
On Wed, 26 Mar 2008, sam <sam.mahindrakar@gmail.com> writes:
> Iam trying to update a database table with approx 45000 rows. Iam not
> updating all rows at a time. Iam updating 60 rows at a given time for
> example. and this is happening in a FOR LOOP. A function that has the
> update statements is called within the loop.
>
> The updates take too long.....is postgres slow in doing updates on
> large tables or is it because of the function call within the loop???

Are there any ON UPDATE CASACADE and FK consistency checks on the
table. Are related columns used during UPDATE INDEXed appropriately?
It'd be helpful if you can supply your table schema and UPDATE query
string.


Regards.

Re: Performance of update

От
Sam Mason
Дата:
On Wed, Mar 26, 2008 at 01:26:03PM -0700, Sam wrote:
> Iam trying to update a database table with approx 45000 rows. Iam not
> updating all rows at a time. Iam updating 60 rows at a given time for
> example. and this is happening in a FOR LOOP. A function that has the
> update statements is called within the loop.
>
> The updates take too long.....is postgres slow in doing updates on
> large tables or is it because of the function call within the loop???

The short answer is, if you can rearrange your code so that you can
do fewer updates that each do more work then things will probably be
quicker.

Each round trip to the database is going to take a fixed amount of time,
so if you're waiting for the database to get back to you after you do
your update then this is going to be a constant cost on each iteration
of your loop.

Additionally, each transaction is going to take a fixed amount of time
to commit things to disk.  Reducing the number of transactions the
database has to perform is generally a good thing for performance, but
if it's not what your application needs then you have to look elsewhere.


  Sam

Re: Performance of update

От
"Albe Laurenz"
Дата:
sam wrote:
> Iam trying to update a database table with approx 45000 rows. Iam not
> updating all rows at a time. Iam updating 60 rows at a given time for
> example. and this is happening in a FOR LOOP. A function that has the
> update statements is called within the loop.
>
> The updates take too long.....is postgres slow in doing updates on
> large tables or is it because of the function call within the loop???

Could you post the functions and the EXPLAIN output
for the SQL statements in the functions?

Yours,
Laurenz Albe

Re: Performance of update

От
sam
Дата:
On Mar 27, 8:28 am, laurenz.a...@wien.gv.at ("Albe Laurenz") wrote:
> sam wrote:
> > Iam trying to update a database table with approx 45000 rows. Iam not
> > updating all rows at a time. Iam updating 60 rows at a given time for
> > example. and this is happening in a FOR LOOP. A function that has the
> > update statements is called within the loop.
>
> > The updates take too long.....is postgres slow in doing updates on
> > large tables or is it because of the function call within the loop???
>
> Could you post the functions and the EXPLAIN output
> for the SQL statements in the functions?
>
> Yours,
> Laurenz Albe
>
> --
> Sent via pgsql-general mailing list (pgsql-gene...@postgresql.org)
> To make changes to your subscription:http://www.postgresql.org/mailpref/pgsql-general

Ok....
The table is a partition of a main table.
Its schema is pretty straight forward with 10 columns.
There is no Fk consistency or UPDATE CASCADE involved not atleast on
the test table that iam using.
I created indexes for colums used in the WHERE clause. It made the
updating much faster.
The function goes something like this:

function getandsetimputedata()
   BEGIN
        LOOP
         for every row in the cursor
           //do some operations
            PERFORM update_data()
         end for
      END LOOP
END

function update_data()
 BEGIN
    EXECUTE the update  statement

   EXCEPTION block
 END

Any other suggestions how i can make this work faster.

Sam