Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 969946327B5; Mon, 9 Mar 2009 16:26:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 82846-02; Mon, 9 Mar 2009 16:26:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ls405.t-com.hr (ls405.t-com.hr [195.29.150.135]) by mail.postgresql.org (Postfix) with ESMTP id 23B5F632492; Mon, 9 Mar 2009 16:26:09 -0300 (ADT) Received: from ls248.t-com.hr (ls248.t-com.hr [195.29.150.237]) by ls405.t-com.hr (Postfix) with ESMTP id 413764120A; Mon, 9 Mar 2009 20:26:07 +0100 (CET) Received: from ls248.t-com.hr (localhost.localdomain [127.0.0.1]) by ls248.t-com.hr (Qmlai) with ESMTP id 3FCC1D5004A; Mon, 9 Mar 2009 20:26:07 +0100 (CET) X-Envelope-Sender: mario.splivalo@megafon.hr Received: from [192.168.10.1] (93-138-145-201.adsl.net.t-com.hr [93.138.145.201]) by ls248.t-com.hr (Qmali) with ESMTP id B0AD15E01E7; Mon, 9 Mar 2009 20:26:06 +0100 (CET) Message-ID: <49B56D4D.9090605@megafon.hr> Date: Mon, 09 Mar 2009 20:26:05 +0100 From: Mario Splivalo User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: pgsql-performance@postgresql.org CC: pgsql-jdbc@postgresql.org Subject: Re: [PERFORM] Query much slower when run from postgres function References: <49B51B60.6030600@megafon.hr> <27649.1236616294@sss.pgh.pa.us> <87fxhmmygj.fsf@meuh.mnc.lan> In-Reply-To: <87fxhmmygj.fsf@meuh.mnc.lan> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-TM-AS-Product-Ver: IMSS-7.0.0.3129-5.5.0.1026-16382.006 X-TM-AS-Result: No--11.750-5.0-31-1 X-imss-scan-details: No--11.750-5.0-31-1 X-TM-AS-User-Approved-Sender: No X-TM-AS-Result-Xfilter: Match text exemption rules:No X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/32 X-Sequence-Number: 19362 Guillaume Cottenceau wrote: >>> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? >> Usually the reason for this is that the planner chooses a different plan >> when it has knowledge of the particular value you are searching for than >> when it does not. > > Yes, and since Mario is coming from JDBC, I'll share my part on > this: I also noticed some very wrong plans in JDBC because of the > "optimization" in prepared statements consisting of planning once > for all runs, e.g. without any parameter values to help planning. > For what is worth: When I call postgres function via JDBC, I have almost the same execution time as when calling function from psql. When I call SELECT COUNT(*)... WHERE... query from JDBC, I again have almost the same execution time as when executing query from psql. Postgres function takes around 200ms, and SELECT query takes around 2-4ms. Mike