Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8A900650146 for ; Tue, 30 Dec 2008 17:40:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 94309-07 for ; Tue, 30 Dec 2008 17:40:28 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.175]) by mail.postgresql.org (Postfix) with ESMTP id D6E8D650134 for ; Tue, 30 Dec 2008 17:40:27 -0400 (AST) Received: by wf-out-1314.google.com with SMTP id 25so5308192wfc.28 for ; Tue, 30 Dec 2008 13:40:26 -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:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=Aa8pIFtVyljiM9wy927fp7VfY2i+KagwqCWi6PmLO8E=; b=jtyWs7yTABjnYT7mDUlL+Jrc8hfRsyZijXFaUF7oCgo5qt/mHcwhytq0gDgPTKZ0Yy N6KTW7I/o/UzYMZ7GNgrmU/pyUP+wfLgg6C3VmSKOFb8FXWuP5FmdzJj7R1Fi94XDpDT C4plyCirkrcY2HBNvGjdhf0DV3W16KndQ9vIk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=E5VfdSAr6tg9Da9RHsjH/JK00s6miJeF3N/8kDzJuOhO7UVBgtW+YmrPD6CpMZhd1f DdjOtoythtU0V4Yegl88Jk8obc92ed9JyvAK7nurnE8XDlxjI4xZeqvoeKTTmI9q9lOW O3rgkMjaeDG2pkjRh6bCHtUTfeifMVYY0XBEQ= Received: by 10.142.241.10 with SMTP id o10mr6274608wfh.112.1230673226692; Tue, 30 Dec 2008 13:40:26 -0800 (PST) Received: by 10.142.255.15 with HTTP; Tue, 30 Dec 2008 13:40:26 -0800 (PST) Message-ID: <33b743250812301340v94547c7j4da09a9725a2d114@mail.gmail.com> Date: Tue, 30 Dec 2008 13:40:26 -0800 From: bricklen To: "Scott Carey" Subject: Re: Poor plan choice in prepared statement Cc: "Scott Marlowe" , "Merlin Moncure" , "pgsql-performance@postgresql.org" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <33b743250812301059u31ce82faw3d72a38280b37402@mail.gmail.com> <33b743250812301214k7a0ec4fby614d693ec7915d3@mail.gmail.com> 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: 200812/236 X-Sequence-Number: 32272 On Tue, Dec 30, 2008 at 1:09 PM, Scott Carey wrote: > There is no way to force Postgres to re-plan a prepared statement. In many cases, this would be a hugely beneficial feature (perhaps part of the definition of the statement?). > > I have had similar issues, and had to code the application to prevent SQL injection (Postgres $ quotes and other stuff is helpful, but not always adequate or easy). With the current state of things, you'll have to often do your SQL injection defense in your application due to this weakness in prepared statements. > > I have also had a case where one query would take a couple hundred ms to parse, but was fairly fast to plan and execute (1/3 the parse cost) -- yet another case where a prepared statement that re-plans each execution would be helpful. At least you can prevent SQL injection and cut the parse cost. Its not all about the cost of planning the query. > Can you point out any standard ways of preventing sql injection (within or without php)? I would really rather not have to roll my own input sanitation code if there are standard methods available. For example, addslashes is apparently not recommended (according to a warning in the postgresql docs at http://wiki.postgresql.org/wiki/8.1.4_et._al._Security_Release_FAQ). Thanks! Bricklen