Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DBEA263514D for ; Tue, 3 Nov 2009 20:02:45 -0400 (AST) 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 27759-04 for ; Wed, 4 Nov 2009 00:02:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f44.google.com (mail-pw0-f44.google.com [209.85.160.44]) by mail.postgresql.org (Postfix) with ESMTP id 7EC246353A4 for ; Tue, 3 Nov 2009 20:02:30 -0400 (AST) Received: by pwj8 with SMTP id 8so3046053pwj.3 for ; Tue, 03 Nov 2009 16:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=Iv7Mv9Av6FAsNZU+MxKG8Ac5tTEScFYw56PEcz+cuJc=; b=Kj2NGpsx0JfwHSoW7P+P3YCqAPZ4xaL3d93QFpOgxYYCvLU8Q9pBwLOyg76CPG6Jdf QHf44t6FQWnwzVfguFKIFTCxmka3ZB+uYMJ5AKKFERcrM8MkeygnSH0o3MXLVGt4OfBl SbSXyjHjBC/PaHHxMlXhPA25EdNB+6t1c8nxs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=IqpmH+ledD33OhEZd0mFXcs3nPUvJ9oJI5VSA21vSuAkFKoOqQ2dcWGKJfmNMv8myM n/WIaEcB/gqb2A0uj/idJwLc9/dUjtXhVwgqL0zcAo0LkUiaxrCxYS7XWqZzeJqE9dei LV2s8h4sQhNyU8BWgXy9n5Yv+lHH9vWEKAeow= Received: by 10.115.117.13 with SMTP id u13mr851445wam.150.1257292948714; Tue, 03 Nov 2009 16:02:28 -0800 (PST) Received: from ?192.168.2.65? (office.squiz.net [203.206.128.174]) by mx.google.com with ESMTPS id 23sm272214pzk.8.2009.11.03.16.02.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 03 Nov 2009 16:02:27 -0800 (PST) Message-ID: <4AF0C48E.8090100@gmail.com> Date: Wed, 04 Nov 2009 11:02:22 +1100 From: Chris User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: David Kerr CC: Craig Ringer , pgsql-performance@postgresql.org Subject: Re: Optimizer + bind variables References: <20091103174729.GA55736@mr-paradox.net> <4AF0C014.4090000@postnewspapers.com.au> <20091103235245.GA77360@mr-paradox.net> In-Reply-To: <20091103235245.GA77360@mr-paradox.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.351 tagged_above=-10 required=5 tests=AWL=0.248, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/33 X-Sequence-Number: 36201 David Kerr wrote: > On Wed, Nov 04, 2009 at 07:43:16AM +0800, Craig Ringer wrote: > - David Kerr wrote: > - > Does/is it possible for the PG optimizer come up with differnet plans when > - > you're using bind variables vs when you send static values? > - > - Yes, if the bind variable form causes your DB access driver to use a > - server-side prepared statement. Pg can't use its statistics to improve > - its query planning if it doesn't have a value for a parameter when it's > - building the query plan. > > hmm, that's a little unclear to me. > > let's assume that the application is using prepare: > > Assuming the database hasn't changed, would: > PREPARE bla1 as SELECT * from users where username = '$1'; > explain execute bla1 > > give the same output as > explain select * from users where username = 'dave'; > > ? No. This is explained in the notes here: http://www.postgresql.org/docs/current/static/sql-prepare.html -- Postgresql & php tutorials http://www.designmagick.com/