Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 597229FB8BB for ; Mon, 4 Jun 2007 21:57:39 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 52898-08 for ; Mon, 4 Jun 2007 21:57:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from syd.object-craft.com.au (ppp167-236-184.static.internode.on.net [59.167.236.184]) by postgresql.org (Postfix) with ESMTP id 647EC9FB295 for ; Mon, 4 Jun 2007 21:57:35 -0300 (ADT) Received: by longblack.object-craft.com.au (Postfix, from userid 1000) id F0D606007A7; Tue, 5 Jun 2007 10:57:31 +1000 (EST) Received: from longblack (localhost [127.0.0.1]) by longblack.object-craft.com.au (Postfix) with ESMTP id DADA66007A2; Tue, 5 Jun 2007 10:57:31 +1000 (EST) To: "Miha D. Puc" cc: pgsql-interfaces@postgresql.org Subject: Re: Bytea network traffic: binary vs text result format In-reply-to: <466299A7.20403@eba.si> References: <466299A7.20403@eba.si> Comments: In-reply-to "Miha D. Puc" message dated "Sun, 03 Jun 2007 12:36:23 +0200." Date: Tue, 05 Jun 2007 10:57:31 +1000 From: Andrew McNamara Message-Id: <20070605005731.F0D606007A7@longblack.object-craft.com.au> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/4 X-Sequence-Number: 6573 >There was some debate recently about using text or binary format. >There's people who would like to use it but have trouble converting >binary encoded results into native types and there's people that say >there's not much performance difference. > >I'd like to stress that performance is very different over slow >network. The biggest difference is for byte where the text format >performance is about 3.5 times worse at inserts and updates and about >2.9 times worse at selects . Here's the reasoning: You're referring to the worst case of the text format - handling pure binary data - and yes, in this case, up to 4 times as many bytes can flow over the network. If the network is your constraining factor, then this will be significant. But in many other cases (fast local network), the disks are the limiting factor, or other data types dominate, and in those cases, the text format can actually be smaller. >So there is a need (people asking) and reason (performance) to use >binary format. But there's a huge drawback - the conversions. It's easy >for varchar, not too bad for basic types (int, float, bool), effort is >needed for timestamp, date, time and numeric is a pain. > >So with all the above there should be a utility for conversion between >binary format and native types and/or string format in libpq. And there's the rub... the "basic" types you mention all have standard C representations, but there is no standard C type for timestamp, date, time and numeric, so what would libpq convert to? Any chosen format will only suite a subset of users, and will result in double conversions for others who are constrained by the existing types used within their application. I'm not sure what the answer is - certainly documenting the wire format would be a good first step. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/