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 1ez5vW-0006n0-FD for pgsql-admin@arkaria.postgresql.org; Thu, 22 Mar 2018 19:31:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ez5vU-0003PC-Jo for pgsql-admin@arkaria.postgresql.org; Thu, 22 Mar 2018 19:31:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ez5vU-0003P3-Bt for pgsql-admin@lists.postgresql.org; Thu, 22 Mar 2018 19:31:04 +0000 Received: from util-st-02.imsweb.com ([204.132.58.65]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ez5vQ-0008BC-C8 for pgsql-admin@lists.postgresql.org; Thu, 22 Mar 2018 19:31:03 +0000 Received: from PAN.omni.imsweb.com (haproxy-st-02 [204.132.58.76]) by util-st-02.imsweb.com (Postfix) with ESMTP id F1263DF7AB; Thu, 22 Mar 2018 15:30:57 -0400 (EDT) Received: from THALASSA.omni.imsweb.com (172.22.64.102) by PAN.omni.imsweb.com (172.22.64.64) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 22 Mar 2018 15:30:57 -0400 Received: from THALASSA.omni.imsweb.com ([172.22.64.102]) by THALASSA.omni.imsweb.com ([172.22.64.102]) with mapi id 15.00.1367.000; Thu, 22 Mar 2018 15:30:57 -0400 From: "Heinemann, Manfred (IMS)" To: Tom Lane CC: "pgsql-admin@lists.postgresql.org" Subject: RE: Function search_path Thread-Topic: Function search_path Thread-Index: AdO7x5WpnFdOXZ+3TX2aPXuhH1G0VQAmi7sAAEIC53AACfROAAEgoc8w Date: Thu, 22 Mar 2018 19:30:56 +0000 Message-ID: References: <5f698c34-d01d-3196-1db4-75ba8f6a37d3@portavita.eu> <2328.1521236730@sss.pgh.pa.us> In-Reply-To: <2328.1521236730@sss.pgh.pa.us> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [204.132.58.76] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >> I have played around with the postgres memory settings and setting searc= h_path on a function causes a lot more memory to be used than if no search_= path was set. > >That's a pretty broad claim with a pretty small amount of evidence offered= . > >I can certainly believe that attaching a SET clause (whether for search_pa= th or any other GUC variable) would have an efficiency impact; one non-obvi= ous example is that it prevents inlining if the function is a SQL function.= But I don't immediately see a reason for major memory consumption from th= at. I suspect what you're seeing is specific to a particular use-case. If= you were to provide a concrete example, we could look into what's happenin= g. > >regards, tom lane Here is an example where I can show significant extra memory consumption wh= en setting search_path on a function: CREATE TABLE test_search_path(date_last_modified timestamp, last_name varch= ar); --populate 1,000,000 rows with random values from 1,000 surnames for 'SURNA= ME' INSERT INTO test_search_path(date_last_modified, last_name) VALUES(clock_ti= mestamp(), 'SURNAME'); CREATE OR REPLACE FUNCTION clean_name_upper(original_name varchar) RETURNS varchar LANGUAGE plpgsql AS $$ BEGIN RETURN trim(upper(original_name)); END; $$ IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION split_name_on_hyphen(original_name character var= ying) RETURNS text[] LANGUAGE plpgsql AS $$ BEGIN RETURN string_to_array(clean_name_upper(original_name), '-'); END; $$ IMMUTABLE STRICT SET search_path =3D '$user'; CREATE INDEX idx_test_search_path_clean_name_upper_last_name ON test_search= _path (clean_name_upper(last_name)); CREATE INDEX idx_test_search_path_split_name_on_hyphen_last_name ON test_se= arch_path USING gin(split_name_on_hyphen(last_name)); UPDATE test_search_path SET date_last_modified =3D (date_last_modified - in= terval '7 days'); This only seems to be an issue when indices exist for both functions and wh= en the inner called function does not have search_path set. Thanks, Manfred ________________________________ Information in this e-mail may be confidential. It is intended only for the= addressee(s) identified above. If you are not the addressee(s), or an empl= oyee or agent of the addressee(s), please note that any dissemination, dist= ribution, or copying of this communication is strictly prohibited. If you h= ave received this e-mail in error, please notify the sender of the error.