Re: Slow planning time for custom function

From: bk(at)e8s(dot)de
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Slow planning time for custom function
Date: 2018-03-25 18:18:44
Message-ID: 4A7D94AA-65BD-4474-BD22-B26A8982B321@e8s.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,

thanks for your help which already resolved the issue for me. I worked through your replies and it is indeed a startup delay for the first call to a plv8 function in a session. I pasted the query plans below for comparison.

```
explain analyze select normalizeunidiff('')

QUERY PLAN
-------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=1)
Planning time: 1863.782 ms
Execution time: 0.022 ms
```

Then I ran again multiple times, to make sure that there was not some kind of startup delay:
```
select normalizeunidiff('');
explain analyze select normalizeunidiff('');

QUERY PLAN
-------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=32) (actual time=0.000..0.001 rows=1 loops=1)
Planning time: 0.190 ms
Execution time: 0.008 ms
```

Thanks again
-Ben

> On 24. Mar 2018, at 02:52, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> wrote:
>
> On 24 March 2018 at 14:35, Andres Freund <andres(at)anarazel(dot)de> wrote:
>> How long does planning take if you repeat this? I wonder if a good chunk
>> of those 1.8s is initial loading of plv8.
>
> Maybe, but it also could be the execution of the function, after all,
> the planner does invoke immutable functions:
>
> # explain verbose select lower('TEST');
> QUERY PLAN
> -------------------------------------------
> Result (cost=0.00..0.01 rows=1 width=32)
> Output: 'test'::text
> (2 rows)
>
> Would be interesting to see what changes without the IMMUTABLE flag.
>
> --
> David Rowley http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Peter 2018-03-26 10:36:13 Re: Should from_collapse be switched off? (queries 10 times faster)
Previous Message David Rowley 2018-03-25 12:24:00 Re: functions: VOLATILE performs better than STABLE