Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dCiOL-0005i5-FM for pgsql-performance@arkaria.postgresql.org; Mon, 22 May 2017 08:08:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dCiOK-0005C9-JH for pgsql-performance@arkaria.postgresql.org; Mon, 22 May 2017 08:08:36 +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.84_2) (envelope-from ) id 1dCiMZ-00026w-8i for pgsql-performance@postgresql.org; Mon, 22 May 2017 08:06:47 +0000 Received: from outgoing7.cpt4.host-h.net ([197.189.247.40]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dCiMU-0005Q1-G2 for pgsql-performance@postgresql.org; Mon, 22 May 2017 08:06:45 +0000 Received: from www20.cpt1.host-h.net ([197.221.2.20]) by antispam4-cpt4.host-h.net with esmtpsa (TLSv1.2:AES128-SHA:128) (Exim 4.86) (envelope-from ) id 1dCiMK-0001Zi-Hh; Mon, 22 May 2017 10:06:37 +0200 Received: from 196-210-197-156.dynamic.isadsl.co.za ([196.210.197.156] helo=DMZHOST) by www20.cpt1.host-h.net with esmtpa (Exim 4.80) (envelope-from ) id 1dCiMJ-00063h-Bh; Mon, 22 May 2017 10:06:31 +0200 Received: from P03867-RiaanS (Unknown [10.100.0.1]) by DMZHOST with ESMTPA ; Mon, 22 May 2017 10:06:18 +0200 Subject: Re: Bulk persistence strategy To: Simon Riggs References: <04c901d2a753$f55de020$e019a060$@exa.co.za> <15c29aeedc8.27e1.e05fafc80f8daf1488764675043d44fb@exa.co.za> <32403.1495377186@sss.pgh.pa.us> <0e47ae52-e80a-fd8e-021c-7c8cc0495b26@exa.co.za> <30684.1495406234@sss.pgh.pa.us> Cc: "pgsql-performa." From: Riaan Stander Message-ID: <85a35463-12e4-8647-e7fb-b11fdddbb122@exa.co.za> Date: Mon, 22 May 2017 10:06:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: smtprelay@exa.co.za X-Virus-Scanned: Clear (ClamAV 0.99.2/23406/Mon May 22 02:55:22 2017) X-Originating-IP: 197.221.2.20 X-SpamExperts-Domain: exa.co.za X-SpamExperts-Username: Authentication-Results: host-h.net; auth=pass (login) smtp.auth=@exa.co.za X-SpamExperts-Outgoing-Class: unsure X-SpamExperts-Outgoing-Evidence: Combined (0.33) X-Recommended-Action: accept X-Filter-ID: s0sct1PQhAABKnZB5plbIWL5vMUYxb2kq1uspbfEA9+ihNzEqHRR3fXVWQ7SEawUiwQzKw+6v3Ca IMG6s7LqJJlV3j2ipgsAbbE1JvuwkkgZ4m00l3uPRdWwNfw+Po+GO76XSTAwtV4mg4i2ouCDa4AU hvIWAV5xUW/+gAh4vXopQF/QbCTfVFU6XKXQXxUORcOb18WfxGyg6Om6u4YYm8HcCwT21N9ycPvA lJovTUyMytmwoSOAsUiZHL4elTOeW/T3iEdLQrEzANTH1RO+ZuWBOXp8nHKe0R+FkIqN7hlBaLCK i/3d82ndyQckqlk5z3irZHx8XwBM/aZ+josQAfUf9oDBqtClgM5jH/om1Q4tH6VyaEKKyFb3KuYS PtYeOngwKsK/v8O00LnH1NcGs0PkGda5olUXOJzJbtkypWIEPaEM6Ls9T603i0+693Pcg6KXIM1o Gpi52wN9xML6BTYYB0K6DpInazve5ezQP+U2yPRk3H1E4ANRdN1BlPI5rJaWDcne6cToXniqtJYh 2fh2wfAJPI99az2gqFCIIfZ1+KzU7SnoXsKZpOw3kjuyUE5+n83VHgUVFZ+GUeLTXJaGzcj+Mc5i sodBI9N2YC4YJXKktT3MPooML3ofVDSL+2eVPGSfsIw7ANTvBNHA8VaBZax/OZ0QHGT/Dj7PZdYj RhAY8Vmf4byZuSD90J4OMtBAYgfXezMRBnbkuMAOc/14r9YOcrnyK6LJ6cx0MKLve9WLLLMSzup8 3yYGWu3FIUIYr6Q5mbbbicQSHcNP9z5kJJv0f6tLOzIIbocGBSNte+4ShnC60suXjzYBg59Zwgy/ UIfKvWT1xkFqx2kvPKHiaNh7OIdzqyWAB3ARFPRqlzW5hxHRDjGA2vz7I/3qLlSv2DcyLDAjh4CC o2us0Q== X-Report-Abuse-To: spam@antispammaster.host-h.net X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org > On 22 May 2017 at 03:14, Riaan Stander wrote: >>> Riaan Stander writes: >>>> The intended use is use-once. The reason is that the statements might >>>> differ per call, especially when we start doing updates. The ideal would >>>> be to just issue the sql statements, but I was trying to cut down on >>>> network calls. To batch them together and get output from one query as >>>> input for the others (declare variables), I have to wrap them in a >>>> function in Postgres. Or am I missing something? In SQL Server TSQL I >>>> could declare variables in any statement as required. >>> Hm, well, feeding data forward to the next query without a network >>> round trip is a valid concern. >>> >>> How stylized are these commands? Have you considered pushing the >>> generation logic into the function, so that you just have one (or >>> a few) persistent functions, and the variability slack is taken >>> up through EXECUTE'd strings? That'd likely be significantly >>> more efficient than one-use functions. Even disregarding the >>> pg_proc update traffic, plpgsql isn't going to shine in that usage >>> because it's optimized for repeated execution of functions. >>> >>> regards, tom lane >> The commands are generated from a complex object/type in the application. >> Some of them can be quite large. With modifications they do state tracking >> too, so that we only update fields that actually changed and can do >> optimistic concurrency checking. >> >> It'll probably make more sense to try create a function per type of object >> that deals with the query generation. That way I can create a Postgres type >> that maps from the application object. >> >> Thanks for the advice. I'll give that a shot. > It sounds like you don't know about anonymous code blocks with DO > https://www.postgresql.org/docs/devel/static/sql-do.html > Yes I do know about that feature. My first implemented generated an anonymous code block, but to my utter dismay once I tried actually doing parameter binding from the application it did not work. This seems to be a Postgres limitation actually stated in the documentation. The anonymous code block is treated as a function body with no parameters. Thanks for the suggestion though. Regards Riaan Stander -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance