Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uly06-0003h8-Ac for pgsql-performance@arkaria.postgresql.org; Mon, 10 Jun 2013 09:02:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uly05-0001tj-O0 for pgsql-performance@arkaria.postgresql.org; Mon, 10 Jun 2013 09:02:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uly04-0001td-Kr for pgsql-performance@postgresql.org; Mon, 10 Jun 2013 09:02:52 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uly00-0005IF-10 for pgsql-performance@postgresql.org; Mon, 10 Jun 2013 09:02:52 +0000 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BDB70448; Mon, 10 Jun 2013 17:02:41 +0800 (CST) Received: from SZXEML403-HUB.china.huawei.com (10.82.67.35) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.1.323.7; Mon, 10 Jun 2013 17:02:35 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml403-hub.china.huawei.com (10.82.67.35) with Microsoft SMTP Server id 14.1.323.7; Mon, 10 Jun 2013 17:02:34 +0800 From: Amit Kapila To: "'Yuri Levinsky'" , "'Ghislain ROUVIGNAC'" , References: <007201ce62a2$56c35930$044a0b90$@kapila@huawei.com> In-Reply-To: Subject: Re: Not same plan between static and prepared query Date: Mon, 10 Jun 2013 14:32:20 +0530 Message-ID: <00e701ce65b9$3f2caa50$bd85fef0$@kapila@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac5ij4wP5JpI2JlZTn2CwA8jHlte+gAEg66QAKBF9MAAJR2kwA== Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: -1.7 (-) 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 Sunday, June 09, 2013 8:45 PM Yuri Levinsky wrote: > Amit, > It's very strength for me to hear that PostgreSQL generate execution > plan for prepared statements during execution, I always was thinking > that the purpose of the prepared statement is to eliminate such > behavior.=20 It doesn't always choose to generate a new plan, rather it is a calculative decision. As far as I understand, it generates custom plan (based on bound parameters) for 5 times and then generates generic plan (not based on bound parameters), after that it compares that if the cost of generic plan is less than 10% more expensive than average custom plan, then it will choose generic plan. > Can it lead to some performance degradation in case of heavy > "update batch", that can run for millions of different values?=20 Ideally it should not degrade performance. What kind of update you have and does the values used for execute can vary plan too much every time? > Is it > some way to give some kind of query hint that will eliminate execution > path recalculations during heavy updates and instruct regarding correct > execution plan? Currently there doesn't exist any way to give any hint. =20 > Sincerely yours, >=20 >=20 > Yuri Levinsky, DBA > Celltick Technologies Ltd., 32 Maskit St., Herzliya 46733, Israel > Mobile: +972 54 6107703, Office: +972 9 9710239; Fax: +972 9 9710222 >=20 > -----Original Message----- > From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance- > owner@postgresql.org] On Behalf Of Amit Kapila > Sent: Thursday, June 06, 2013 1:41 PM > To: 'Ghislain ROUVIGNAC'; pgsql-performance@postgresql.org > Subject: Re: [PERFORM] Not same plan between static and prepared query >=20 >=20 > On Thursday, June 06, 2013 1:56 PM Ghislain ROUVIGNAC wrote: > > Hello, >=20 >=20 > > We have a strange issue related to a prepared statement. >=20 >=20 > > We have two equals queries where the sole difference is in the limit. > > - The first is hard coded with limit 500. > > - The second is prepared with limit $1 ($1 is bound to 500). >=20 >=20 > > PostgreSQL give us two different plans with a huge execution time for > > the > prepared query: >=20 > It can generate different plan for prepared query, because optimizer > uses default selectivity in case of bound parameters (in your case > limit $1). >=20 >=20 > > We met the same behaviour with both : > > - PostgreSQL 8.4.8 on Windows 2008 (Prod) > > -=A0PostgreSQL=A08.4.8 and=A08.4.17 on Windows 7 (Dev) >=20 > From PostgreSQL 9.2, it generates plan for prepared query during > execution (Execute command) as well. > So I think you will not face this problem in PostgreSQL 9.2 and above. >=20 > With Regards, > Amit Kapila. >=20 >=20 >=20 > -- > Sent via pgsql-performance mailing list (pgsql- > performance@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance >=20 > This mail was received via Mail-SeCure System. >=20 >=20 >=20 >=20 > -- > Sent via pgsql-performance mailing list (pgsql- > performance@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance