Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 61FBF1337B4E for ; Thu, 30 Sep 2010 16:14:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 87293-05 for ; Thu, 30 Sep 2010 19:14:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh7.mail.rice.edu (mh7.mail.rice.edu [128.42.199.46]) by mail.postgresql.org (Postfix) with ESMTP id 2CA7C1337B4A for ; Thu, 30 Sep 2010 16:14:11 -0300 (ADT) Received: from mh7.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh7.mail.rice.edu (Postfix) with ESMTP id 1ECDA28F755; Thu, 30 Sep 2010 14:14:10 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.4 at mh7.mail.rice.edu, auth channel Received: from mh7.mail.rice.edu ([127.0.0.1]) by mh7.mail.rice.edu (mh7.mail.rice.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id lbFeCIGyPenl; Thu, 30 Sep 2010 14:14:10 -0500 (CDT) X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh7.mail.rice.edu (Postfix) with ESMTP id D9F0C28F752; Thu, 30 Sep 2010 14:14:09 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 138132D5A6; Thu, 30 Sep 2010 14:14:08 -0500 (CDT) Date: Thu, 30 Sep 2010 14:14:08 -0500 From: Kenneth Marshall To: Dmitriy Igrishin Cc: Steve , pgsql-sql@postgresql.org Subject: Re: Question about PQexecParams Message-ID: <20100930191408.GJ14003@aart.is.rice.edu> References: <20100911124423.75020@gmx.net> <20100922100715.123530@gmx.net> <20100930171253.GI14003@aart.is.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/120 X-Sequence-Number: 34651 On Thu, Sep 30, 2010 at 10:30:16PM +0400, Dmitriy Igrishin wrote: > Hey Kenneth, > > Thank you for solution. But sorry, personally, I don't clearly > understand the benefits of this code compared with using > simple array literals or even array constructors... > Conversion "overheads" from text? Doubtfully... > > -- > // Dmitriy. There are three benefits: - reduces the CPU overhead in both the client and the DB server for converting to/from ASCII numbers - decreases the amount of network traffic by more than 1/2 - binary transmission of query parameters helps protect against SQL injection attacks Obviously, this is not as important for low performance systems, with the possible exception of preventing SQL injection attacks, but on high performance systems, minimizing the CPU overhead due to data conversions is very useful indeed. Whether or not someone chooses to use it would need to be evaluated on a case-by-case basis. I posted the code because the details on how to use binary array transmission needed close examination of the documentation as well as the database sources. If you are using PostgreSQL 8.3 or higher, and can use an add on library, libpqtypes provides a very nice and very useful API for managing binary parameter transmission. I really hope that it could be included in the core PostgreSQL to help others avoid the need to troll through the grotty inner-workings of the database to figure out how to do this using just libpq. Cheers, Ken