Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dCcsF-0003HF-Kv for pgsql-performance@arkaria.postgresql.org; Mon, 22 May 2017 02:15:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dCcsE-00054u-2W for pgsql-performance@arkaria.postgresql.org; Mon, 22 May 2017 02:15:06 +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 1dCcsD-00054b-JC for pgsql-performance@postgresql.org; Mon, 22 May 2017 02:15:05 +0000 Received: from outgoing14.cpt4.host-h.net ([197.189.249.71]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dCcs9-0007Bm-BH for pgsql-performance@postgresql.org; Mon, 22 May 2017 02:15:03 +0000 Received: from www20.cpt1.host-h.net ([197.221.2.20]) by antispam3-cpt4.host-h.net with esmtpsa (TLSv1.2:AES128-SHA:128) (Exim 4.86) (envelope-from ) id 1dCcs0-0002aM-Iv; Mon, 22 May 2017 04:14:55 +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 1dCcrx-0005Qk-NB; Mon, 22 May 2017 04:14:49 +0200 Received: from P03867-RiaanS (Unknown [10.0.0.23]) by DMZHOST with ESMTPA ; Mon, 22 May 2017 04:14:36 +0200 Subject: Re: Bulk persistence strategy To: Tom Lane 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-performance@postgresql.org From: Riaan Stander Message-ID: Date: Mon, 22 May 2017 04:14:35 +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: <30684.1495406234@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: smtprelay@exa.co.za X-Virus-Scanned: Clear (ClamAV 0.99.2/23405/Sun May 21 18:55:10 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/+gAh4vXpjZhs03qX+S5y/Ez5w8rR2RcOb18WfxGyg6Om6u4YYm2pH9cSSExIV46TR ReXiZc6MytmwoSOAsUiZHL4elTOeW/T3iEdLQrEzANTH1RO+ZuWBOXp8nHKe0R+FkIqN7hlBaLCK i/3d82ndyQckqlk5z3irZHx8XwBM/aZ+josQAfUf9oDBqtClgM5jH/om1Q4tH6VyaEKKyFb3KuYS PtYeOngwKsK/v8O00LnH1NcGs0PkGda5olUXOJzJbtkypWIEPaEM6Ls9T603i0+693PcDLiCdXYi Jn8zoNFWujxaUjYYB0K6DpInazve5ezQP+U2yPRk3H1E4ANRdN1BlPI5rJaWDcne6cToXniqtJYh 2fh2wfAJPI99az2gqFCIIfZ1+KzU7SnoXsKZpOw3kjuyfWVvO29wuJsChK5I9zbUmZaGzcj+Mc5i sodBI9N2YC4YJXKktT3MPooML3ofVDSL+2eVPGSfsIw7ANTvBNHA8VaBZax/OZ0QHGT/Dj7PZdZ9 A4yueqaNzsXwjbLBNpkpMtBAYgfXezMRBnbkuMAOc6LId/tNPI1JonDDAePyhC/ve9WLLLMSzup8 3yYGWu3FIUIYr6Q5mbbbicQSHcNP9z5kJJv0f6tLOzIIbocGBSMsuxw7bdAwcqEEBoE9uGXwb6it Q/DYWZjYb5QoZ23GT4vrg+o+DbR9cyhvlML6z+umMi5XUpTVQ5y/LLcx9Z1wMS+4ayUpOtEhdxek WDmK9g== 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 > 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. 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