Em 16 de dezembro de 2010 15:17, [email protected] <
[email protected]> escreveu:

>  CREATE OR REPLACE FUNCTION "public"."f_rep_tarefa_concluida" (
> )
> RETURNS trigger AS
> $body$
> DECLARE
>     rec           RECORD;
>     dataini      TIMESTAMP(0);
>     datafim     TIMESTAMP(0);
>     flag           BOOLEAN;
> BEGIN
>     IF OLD.estado = '0' and NEW.estado = '1' THEN
>         perform zera_calc_rep(NEW.idrepesportesmt);
>
>         FOR rec IN select idrel_tarefasrep, idprog from rel_tarefasrep
> where idrepesportesmt = NEW.idrepesportesmt LOOP
>             dataini = now();
>             flag = f_rodar_reportagem(NEW.idrepesportesmt,
> rec.idprog);
>             datafim = now();
>
>             IF flag = true THEN
>               update rel_tarefasrep set
>                      rodado = true
>               where idrel_tarefasrep = rec.idrel_tarefasrep;
>
> --               insert into hist_relatorio_reportagem values (0,
> rec.idrel_tarefasrep, dataini, datafim, '',
> '0');
>             END IF;
>         END LOOP;
>     END IF;
>
>     RETURN NULL;
> END;
> $body$
> LANGUAGE 'plpgsql'
> VOLATILE
> CALLED ON NULL INPUT
> SECURITY INVOKER
> COST 100;
>
>

Me parece que vc necessita otimizar essas suas funções ou utilizar outra
abordagem. Algumas informações:

*  Quantos registros retorna essa sua query;
  " FOR rec IN select idrel_tarefasrep, idprog from rel_tarefasrep where
idrepesportesmt = NEW.idrepesportesmt LOOP "

* Quanto tempo leva para processar a PL:
  "             flag = f_rodar_reportagem(NEW.idrepesportesmt, rec.idprog);
           "


Vc rodou um EXPLAIN para observar os planos das queries envolvidas nessa sua
PL??? Seria interessante fazer isso para poder detectar o(s) gargalo(s).

-- 
Fabrízio de Royes Mello
>> Blog sobre TI: http://fabriziomello.blogspot.com
>> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a