Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6B06FB5DBDF for ; Wed, 29 Jun 2011 15:37:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 50222-02 for ; Wed, 29 Jun 2011 18:37:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from morework.geizhals.at (morework.geizhals.at [78.142.138.3]) by mail.postgresql.org (Postfix) with ESMTP id 7A76FB5DBD0 for ; Wed, 29 Jun 2011 15:37:29 -0300 (ADT) Received: from localhost (morework [127.0.0.1]) by morework.geizhals.at (Postfix) with ESMTP id 673DF124828D; Wed, 29 Jun 2011 20:37:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at geizhals.at Received: from morework.geizhals.at ([127.0.0.1]) by localhost (morework.geizhals.at [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y9AjIHWMfVjX; Wed, 29 Jun 2011 20:36:54 +0200 (CEST) Received: from klump-pc.ghoffice (mjyrouter [213.235.209.145]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mjy) by morework.geizhals.at (Postfix) with ESMTPSA; Wed, 29 Jun 2011 20:36:54 +0200 (CEST) Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: pgsql-performance@postgresql.org, "Svetlin Manavski" Subject: Re: is parallel union all possible over dblink? References: Date: Wed, 29 Jun 2011 20:37:18 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Marinos Yannikos" Organization: Preisvergleich Internet Services AG Message-ID: In-Reply-To: User-Agent: Opera Mail/11.11 (Win32) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/270 X-Sequence-Number: 44203 On Wed, 29 Jun 2011 13:55:58 +0200, Svetlin Manavski wrote: > Question: Is there a way to get the same result from within a PL/pgSQL > function but running all the sub-queries in parallel? In case it is not > directly available, which one would be the simplest way to implement it > in > my application? (I am very keen to avoid the obvious solution of an > additional multi-threaded layer which would do it out of the RDBMS) Have you tried dblink_send_query() + dblink_get_results() yet? http://www.postgresql.org/docs/current/static/contrib-dblink-send-query.html You'd have to do something like this to your queries [untested]: select dblink_send_query('remote1','select * from appqosfe.F_total_utilization(1306918800000000000::INT8, NULL, 60000000000::INT8, NULL)'); (select * from appqosfe.F_total_utilization(1306918800000000000::INT8, NULL, 60000000000::INT8, NULL)) UNION ALL (SELECT * from dblink_get_result('remote1') as T1(detectroid numeric, timegroup numeric, numbytes numeric, numpackets numeric)) order by timegroup asc; i.e. start your remote query/-ies asynchronously, then collect the results in the UNION query. At least in theory it should work... Regards, Marinos