From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | Omar Zeballos <ozeballos(at)kantutani(dot)com> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: Funcion SQL mas lenta que un SQL |
Date: | 2008-03-11 14:18:08 |
Message-ID: | 20080311141808.GF9116@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Omar Zeballos escribió:
> CREATE OR REPLACE FUNCTION sql_regenerastock(p_fecha date, p_codprod
> numeric)
> RETURNS SETOF regenerastock AS $BODY$
> select a,b,c from tabla1 where fecha<=p_fecha and codproducto=p_codprod
> union all
> select a,b,c from tabla2 where fecha<=p_fecha and codproducto=p_codprod
> union all
> select a,b,c from tabla3 where fecha<=p_fecha and codproducto=p_codprod
> LANGUAGE 'sql' VOLATILE;
>
> y ejecuto select * from sql_regenerastock(current_date,100) esta tarda
> 70seg
> No es un problema de indices, es un problema de colocar una consulta en
> una funcion SQL y utlizarla, porque si observas bien es la misma
> consulta,
La consulta no es la misma, porque el optimizador se comporta distinto
en cada caso. En el segundo caso puedes examinar que es lo que piensa
el optimizador de la siguiente manera:
prepare foo as
select a,b,c from tabla1 where fecha<=$2 and codproducto=$1
union all
select a,b,c from tabla2 where fecha<=$2 and codproducto=$1
union all
select a,b,c from tabla3 where fecha<=$2 and codproducto=$1
explain analyze execute foo(100, current_date)
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2008-03-11 14:19:14 | Re: cambiar encoding |
Previous Message | MIGUEL CANCHAS | 2008-03-11 14:11:06 | RE: Demora mi consulta |