For Loop using row_data to increase performance - Mailing list pgsql-general

From John777
Subject For Loop using row_data to increase performance
Date
Msg-id 93d01396-cb6b-415c-a1ab-c458ea943b23@b9g2000pri.googlegroups.com
Whole thread Raw
Responses Re: For Loop using row_data to increase performance  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
List pgsql-general
Hi,

Here are sample stat:
 - Template_product has 1,033040 rows
 - template_all_in_one has 93,796,400 rows

I basically need to calculate the total for each article in
template_all_in_one and update it to Template_product.

What is the best way to improve the performance? I already have 7
indexes specify for the column.  My desktop has 4quad and 8 GB memory.
it only used up 1 GB memory. is it possible to increase the memory, so
the query will use more memory and end up faster performance?

===================================
CREATE OR REPLACE FUNCTION test_update_template_db()
  RETURNS integer AS
$BODY$
  DECLARE
     text_manipulation TEXT :='';
    row_data template_product%ROWTYPE;

  BEGIN

    FOR row_data IN SELECT * FROM template_product LOOP

       update template_product set total_all_in_one = (select count(*)
from template_all_in_one where template_article_name =
row_data.template_article_name)
       where template_product.id = row_data.id;

    END LOOP;

    RETURN 1;
  END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;
ALTER FUNCTION test_update_template_db() OWNER TO postgres;
========================================

pgsql-general by date:

Previous
From: Cyril Scetbon
Date:
Subject: kernel version impact on PostgreSQL performance
Next
From: Cyril Scetbon
Date:
Subject: kernel version impact on PostgreSQL performance