Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U9HkG-0007zI-Lf for pgsql-performance@arkaria.postgresql.org; Sat, 23 Feb 2013 16:14:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U9HkG-0002dm-5u for pgsql-performance@arkaria.postgresql.org; Sat, 23 Feb 2013 16:14:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U9HkF-0002dh-Ex for pgsql-performance@postgresql.org; Sat, 23 Feb 2013 16:14:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U9HkD-0000gS-Bd for pgsql-performance@postgresql.org; Sat, 23 Feb 2013 16:14:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r1NGEXms002530; Sat, 23 Feb 2013 11:14:34 -0500 (EST) From: Tom Lane To: Heikki Linnakangas cc: Markus Schulz , pgsql-performance@postgresql.org Subject: Re: BUG: endless lseek(.., SEEK_END) from select queries on x64 builds In-reply-to: <5128E632.2040209@vmware.com> References: <201302220925.26460.msc@antzsystem.de> <5127741D.6090907@vmware.com> <201302221910.25271.msc@antzsystem.de> <5128E632.2040209@vmware.com> Comments: In-reply-to Heikki Linnakangas message dated "Sat, 23 Feb 2013 17:54:26 +0200" Date: Sat, 23 Feb 2013 11:14:33 -0500 Message-ID: <2529.1361636073@sss.pgh.pa.us> 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 Heikki Linnakangas writes: > You can take the query, replace the ? parameter markers with $1, $2, and > so forth, and explain it with psql like this: > prepare foo (text) as select * from mytable where id = $1; > explain analyze execute foo ('foo'); > On 9.2, though, this will explain the specific plan for those > parameters, so it might not be any different from what you already > EXPLAINed. You can tell whether you're getting a generic or custom plan by noting whether the explain output contains $n symbols or the values you put in. In 9.2, the first five attempts will always produce custom plans, but on the sixth and subsequent attempts you will get a generic plan, if the plancache logic decides that it's not getting any benefit out of custom plans. Here's a trivial example: regression=# prepare foo(int) as select * from tenk1 where unique1 = $1; PREPARE regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = 42) (2 rows) regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = 42) (2 rows) regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = 42) (2 rows) regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = 42) (2 rows) regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = 42) (2 rows) regression=# explain execute foo(42); QUERY PLAN ----------------------------------------------------------------------------- Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244) Index Cond: (unique1 = $1) (2 rows) It's switched to a generic plan after observing that the custom plans weren't any cheaper. Once that happens, subsequent attempts will use the generic plan. (Of course, in a scenario where the custom plans do provide a benefit, it'll keep using those.) regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance