Re: SQL functions not being inlined

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Evan Martin <postgresql(at)realityexists(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL functions not being inlined
Date: 2012-05-02 03:44:16
Message-ID: 28134.1335930256@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Evan Martin <postgresql(at)realityexists(dot)net> writes:
> Some of my functions are running much slower than doing the same query
> "inline" and I'd like to know if there's a way to fix that. ...
> This is quite slow, especially when I have a WHERE clause that narrows
> down the set of rows from 100,000 to 10 or so. I suspect it's evaluating
> the function first and filtering it afterwards and perhaps not using the
> index, either.

Well, rather than suspecting, you should use EXPLAIN to find out whether
the functions are inlined or not. The particular example you give here
seems inlinable to me, but maybe some of your other cases aren't.

I concur with the other respondent that OVERLAPS is not the most
efficient way to deal with the sort of condition you have here, either.
Postgres basically doesn't know how to optimize OVERLAPS at all, whereas
the planner has heard of BETWEEN and other simple-comparison constructs.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2012-05-02 03:50:38 Re: installation of plpython2.7
Previous Message Chris Angelico 2012-05-02 03:23:14 Re: SQL functions not being inlined