Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f2QPn-0001Vw-03 for pgsql-general@arkaria.postgresql.org; Sun, 01 Apr 2018 00:00:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f2QPl-0006CR-Uh for pgsql-general@arkaria.postgresql.org; Sun, 01 Apr 2018 00:00:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f2QPk-0006CA-2Z for pgsql-general@lists.postgresql.org; Sun, 01 Apr 2018 00:00:05 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f2QPf-00029l-9d for pgsql-general@postgresql.org; Sun, 01 Apr 2018 00:00:02 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 43DE320B3E; Sat, 31 Mar 2018 19:59:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 31 Mar 2018 19:59:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=F0BLHzbauAnM3Zcz5eckLhd+Y5Dg8 sZcxos0mzEzYIg=; b=DTMt/tn/BC/VkocZK2ubfwljXWS7IEu1GZA/2m1IrqAsq DNk/MJuR4nQHPL/WMZ68Rpg1GwKkOFl+u7HJFDVvdSAf22KumPPp6So0/lXJ/7Zu 179kGAGusQJq4PC8Q3nUahX6GeL6FCsorqMKYqMUY/aRVITkzt3LLwggRRXtCJjs nR/PSjlNybvq9FHH4gi4Uf3PGzeM2bvDUvUXqrgcStk2i8t6/CnZjpbQi8UnTMT4 7TYvtVEUY6ixDt8XbGCohvkM4JR+wVUCGQ6Vw3GihctoOkPsxgq5NiPFwudCEkng Q5Tpc9Btz2oHlF0wLnKm8+qWGEQvezN6Rr2ovT+xg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=F0BLHz bauAnM3Zcz5eckLhd+Y5Dg8sZcxos0mzEzYIg=; b=WWciK9qWq8ZB8G3eX7ST+I jjr7Vn+q4iVaetsb+QmNKRmfoSS5JRyX+pg4PL+U7sdiCDkAJvSC8vnFi3k4woLk FJoH8ia5hHbQKg29YoT5iSi84ZkFxMVutu9F+MeDZMvc3YMLexUT0IP4RzniXPqm SrAvQIKRVimzso3DsfEbvxuENeBXH20qzvSB0McgM1QyEkPQI9cJBzOBJJaD3dKz wqyiTYpBrTvIxTj8glqJr4f2bHsi2TBaHHMKvS0EaTgnhVRIrdLq0SFWwd1eAlX2 VU5idrGU9erYHs4XHIClOYpHGm4B2Y0d2M+QLkcyvgqp6mnqMes1KnVL8rKRT/mQ == X-ME-Sender: Received: from [192.168.1.2] (71-35-123-124.tukw.qwest.net [71.35.123.124]) by mail.messagingengine.com (Postfix) with ESMTPA id C960410257; Sat, 31 Mar 2018 19:59:56 -0400 (EDT) Subject: Re: unreliable behaviour of track_functions To: pinker , pgsql-general@postgresql.org References: <1522539643653-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <650a05f5-2926-5a63-e653-2ae5aa903547@aklaver.com> Date: Sat, 31 Mar 2018 16:59:56 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1522539643653-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/31/2018 04:40 PM, pinker wrote: > Hi All! > > I've been experimenting with track_functions options and what I've saw it's > really puzzling me. > Documentation says: > / SQL-language functions that are simple enough to be "inlined" into the > calling query will not be tracked, regardless of this setting./ > > But it came up, it depends on much more factors, like duration or placing it > in the query, it is totally non-deterministic behaviour. > > This really simple SQL function: > CREATE FUNCTION a(a bigint) > RETURNS bigint > STABLE > LANGUAGE SQL > AS $$ > SELECT $1 > $$; > > Is not shown in the pg_stat_user_functions at all. It is started to be shown > when one line: > select pg_sleep(1); > > is added??? > > Another one, gets tracked only if I use: > SELECT get_unique_term(2556); > > If it lands in FROM then it's not tracked... > SELECT * FROM get_unique_term(2556); > > That's the body of the function: > CREATE FUNCTION get_unique_term(i_game_pin bigint) > RETURNS TABLE(term text, category text) > STABLE > LANGUAGE SQL > AS $$ > SELECT > i.term, > i.dict_category_id > FROM (SELECT > categories.term, > categories.dict_category_id > FROM categories > EXCEPT ALL > SELECT > games.term, > games.category > FROM games > WHERE game_pin = $1) i > ORDER BY (random()) > LIMIT 1; > $$; > > What's going on here? That's pretty unreliable behaviour... ?: https://www.postgresql.org/docs/10/static/monitoring-stats.html#PG-STAT-USER-FUNCTIONS-VIEW "...But if you want to see new results with each query, be sure to do the queries outside any transaction block. Alternatively, you can invoke pg_stat_clear_snapshot(), which will discard the current transaction's statistics snapshot (if any). The next use of statistical information will cause a new snapshot to be fetched. A transaction can also see its own statistics (as yet untransmitted to the collector) in the views pg_stat_xact_all_tables, pg_stat_xact_sys_tables, pg_stat_xact_user_tables, and pg_stat_xact_user_functions. These numbers do not act as stated above; instead they update continuously throughout the transaction. " > > > My version of postgres: > PostgreSQL 9.6.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 > 20140911 (Red Hat 4.8.3-9), 64-bit > > show track_functions; > track_functions > ----------------- > all > (1 wiersz) > > > > > > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com