pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: pinker <pinker@onet.eu>
To: pgsql-general@postgresql.org
Subject: Re: unreliable behaviour of track_functions
Date: Sun, 1 Apr 2018 09:29:16 -0700
Message-ID: <370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com> (raw)
In-Reply-To: <1522587735746-0.post@n3.nabble.com>
References: <1522539643653-0.post@n3.nabble.com>
	<650a05f5-2926-5a63-e653-2ae5aa903547@aklaver.com>
	<1522541842492-0.post@n3.nabble.com>
	<d2e4fe1a-0e72-9cab-228a-d7068ee5712d@aklaver.com>
	<1522587735746-0.post@n3.nabble.com>

On 04/01/2018 06:02 AM, pinker wrote:
> I mean this part describing track_function:
> 
> https://www.postgresql.org/docs/10/static/runtime-config-statistics.html
> 
> Enables tracking of function call counts and time used. Specify pl to track
> only procedural-language functions, all to also track SQL and C language
> functions. The default is none, which disables function statistics tracking.
> Only superusers can change this setting.
> 
> Note
> SQL-language functions that are simple enough to be “inlined” into the
> calling query will not be tracked, regardless of this setting.
> 
> Only case described here, that exclude function from being tracked it's
> inlining, not the time and not the place in the query.

The below might help:

https://wiki.postgresql.org/wiki/Inlining_of_SQL_functions

In particular for your second case(place in query):

" Table functions

A table function call is any instance where func(args) appears where a 
table is expected. (This is, for most functions, a PostgreSQL extension 
to the SQL standard.) For example:

select * from func(123);
"

For your first case:

Inlining conditions for scalar functions

"the function body consists of a single, simple, SELECT expression"

So from your OP:

CREATE FUNCTION a(a bigint)
   RETURNS bigint
STABLE
LANGUAGE SQL
AS $$
SELECT $1
$$;

If you change to:

CREATE FUNCTION a(a bigint)
   RETURNS bigint
STABLE
LANGUAGE SQL
AS $$
SELECT 'test';
SELECT $1
$$;

then before change:

test=> select * from pg_stat_user_functions ;
  funcid  | schemaname | funcname | calls | total_time | self_time
---------+------------+----------+-------+------------+-----------
  1386647 | public     | a        |     2 |   1251.598 |  1251.598
(1 row)


after change:

test=> select * from pg_stat_user_functions ;
  funcid  | schemaname | funcname | calls | total_time | self_time
---------+------------+----------+-------+------------+-----------
  1386647 | public     | a        |     3 |   1251.682 |  1251.682





> So I would expect that pg_stat_user_function will show me that my function
> was executed. Good that are other ways to do it, but changing
> track_functions to 'all' I would expect all calls will be tracked...
> 
> 
> 
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (8+ messages)

Message-ID: <370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com>
Permalink:  ../370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com/
Also on:    postgresql.org/message-id/370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, pinker@onet.eu
  Subject: Re: unreliable behaviour of track_functions
  In-Reply-To: <370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com>
  References: <1522539643653-0.post@n3.nabble.com> <650a05f5-2926-5a63-e653-2ae5aa903547@aklaver.com> <1522541842492-0.post@n3.nabble.com> <d2e4fe1a-0e72-9cab-228a-d7068ee5712d@aklaver.com> <1522587735746-0.post@n3.nabble.com> <370eb893-48e8-8fa2-9ecf-c3e77e74cdc1@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox