Re: Rendimiento de funciones

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Juan Pablo Espino <jp(dot)espino(at)gmail(dot)com>
Cc: Leonardo Boet Sánchez <boet(at)gtm(dot)tel(dot)etecsa(dot)cu>, pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Rendimiento de funciones
Date: 2005-03-18 20:30:37
Message-ID: 20050318203037.GC14739@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On Fri, Mar 18, 2005 at 01:03:47PM -0500, Juan Pablo Espino wrote:

> On Fri, 18 Mar 2005 13:50:29 -0400, Alvaro Herrera
> <alvherre(at)dcc(dot)uchile(dot)cl> wrote:

> > Usan distinta infraestructura, asi que en realidad depende de lo que
> > estes haciendo. Con plpgsql se guarda el parse tree y los planes de
> > ejecucion de las consultas, a menos que uses EXECUTE. Por lo tanto si
> > usas esto ultimo muy a menudo, el rendimiento tiende a bajar.
>
> > Por otro lado algunas funciones SQL se procesan "inline" en las
> > consultas, por lo tanto el plan de ejecucion las considera como si fueran
> > parte de la consulta y no como objetos opacos (que es lo que sucede con
> > plpgsql y el resto de las funciones)
>
> No comprendo muy bien y me interesa esta parte, me podrías sugerir
> alguna lectura?

Cual parte? Las funciones inline? No hay mucho que leer, a menos que
sea el codigo: src/backend/optimizer/util/clauses.c:inline_function()

/*
* inline_function: try to expand a function call inline
*
* If the function is a sufficiently simple SQL-language function
* (just "SELECT expression"), then we can inline it and avoid the rather
* high per-call overhead of SQL functions. Furthermore, this can expose
* opportunities for constant-folding within the function expression.
*
* We have to beware of some special cases however. A directly or
* indirectly recursive function would cause us to recurse forever,
* so we keep track of which functions we are already expanding and
* do not re-expand them. Also, if a parameter is used more than once
* in the SQL-function body, we require it not to contain any volatile
* functions (volatiles might deliver inconsistent answers) nor to be
* unreasonably expensive to evaluate. The expensiveness check not only
* prevents us from doing multiple evaluations of an expensive parameter
* at runtime, but is a safety value to limit growth of an expression due
* to repeated inlining.
*
* We must also beware of changing the volatility or strictness status of
* functions by inlining them.
*
* Returns a simplified expression if successful, or NULL if cannot
* simplify the function.
*/

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"There is evil in the world. There are dark, awful things. Occasionally, we get
a glimpse of them. But there are dark corners; horrors almost impossible to
imagine... even in our worst nightmares." (Van Helsing, Dracula A.D. 1972)

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Diego Gil 2005-03-18 20:32:26 Re: Consulta sobre Hora
Previous Message Germán Poó Caamaño 2005-03-18 20:29:56 Re: Consulta sobre Hora