Re: Query much slower when run from postgres function

From: Tom Lane
Subject: Re: Query much slower when run from postgres function
Date: ,
Msg-id: 14317.1236628318@sss.pgh.pa.us
(view: Whole thread, Raw)
In response to: Re: Query much slower when run from postgres function  (Mario Splivalo)
Responses: Re: Query much slower when run from postgres function  (Mario Splivalo)
List: pgsql-performance

Tree view

Query much slower when run from postgres function  (Mario Splivalo, )
 Re: Query much slower when run from postgres function  (Tom Lane, )
  Re: Query much slower when run from postgres function  (Guillaume Cottenceau, )
   Re: [JDBC] Query much slower when run from postgres function  (Guillaume Smet, )
    Re: [JDBC] Query much slower when run from postgres function  (Tom Lane, )
     Re: [JDBC] Query much slower when run from postgres function  (Andreas Wenk, )
     Re: [JDBC] Query much slower when run from postgres function  (Dave Cramer, )
      Re: [JDBC] Query much slower when run from postgres function  (James Mansion, )
    Re: [JDBC] Query much slower when run from postgres function  (Scott Carey, )
   Re: Query much slower when run from postgres function  (Mario Splivalo, )
  Re: Query much slower when run from postgres function  (Mario Splivalo, )
   Re: Query much slower when run from postgres function  (Tom Lane, )
    Re: Query much slower when run from postgres function  (Mario Splivalo, )
     Re: Query much slower when run from postgres function  (Tom Lane, )
  Re: Query much slower when run from postgres function  ( (Frank Ch. Eigler), )
   Re: Query much slower when run from postgres function  (Tom Lane, )
    Re: Query much slower when run from postgres function  (decibel, )
     Re: Query much slower when run from postgres function  (Віталій Тимчишин, )
 Re: Query much slower when run from postgres function  (decibel, )

Mario Splivalo <> writes:
> Is this difference normal?

It's hard to tell, because you aren't comparing apples to apples.
Try a prepared statement, like

prepare foo(int) as
SELECT
    COUNT(*)::int4
FROM
    _v1
WHERE
    service_id = $1
;

execute foo(504);

which should produce results similar to the function.  You could
then use "explain analyze execute" to probe further into what's
happening.

            regards, tom lane


pgsql-performance by date:

From: Mark Wong
Date:
Subject: Re: DBT Presentation Location?
From: Scott Carey
Date:
Subject: Re: [JDBC] Query much slower when run from postgres function