pg.ddx.io  postgis-devel@lists.osgeo.org mailing list archive (PostGIS development)  
help / color / mirror / Atom feed
[postgis-devel] JDBC & WKB - 400% overhead
10+ messages / 4 participants
[nested] [flat]

* [postgis-devel] JDBC & WKB - 400% overhead
@ 2005-02-22 18:39 dblasby at openplans.org <dblasby@openplans.org>
  2005-02-22 19:35 ` [postgis-devel] JDBC & WKB - 400% overhead Paul Ramsey <pramsey@refractions.net>
  2005-02-23 14:57 ` [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  0 siblings, 2 replies; 10+ messages in thread

From: dblasby at openplans.org @ 2005-02-22 18:39 UTC (permalink / raw)

I was checking to see if the WKB (postgis 1.0) was actually transiting
"in binary" from the server (postgresql 8) to a JDBC (also postgresql
8) client.

..
ResultSet rs2 = st.executeQuery("select 5::float8,asBinary('POINT(0
0)')");
rs2.next();
byte[] bs = rs2.getBytes(2);
assertTrue(bs.length == 21);

The WKB representation of a 'POINT(0 0)' is 21 bytes long (1 byte for
xdr/ndr flag, 4 bytes for type, and 2 8-byte doubles = 21 bytes).

If you step through the executeQuery() command in the postgresql driver,
you'll eventually end up in PGStream#ReceiveTupleV3().  This is where
the actual data is received from the database.

It clearly receives 84 bytes of data from the server.  This is the bytea
text representation:
\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000

The ResultSet#getBytes() function converts this to a byte[].

dave




----------------------------------------------------------
This mail sent through IMP: https://webmail.limegroup.com/




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-22 18:39 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
@ 2005-02-22 19:35 ` Paul Ramsey <pramsey@refractions.net>
  1 sibling, 0 replies; 10+ messages in thread

From: Paul Ramsey @ 2005-02-22 19:35 UTC (permalink / raw)

This is with an ascii cursor, yes?
I wonder why they chose such a fluffy representation for the bytea 
canonical form.
P.

dblasby at openplans.org wrote:

> I was checking to see if the WKB (postgis 1.0) was actually transiting
> "in binary" from the server (postgresql 8) to a JDBC (also postgresql
> 8) client.
> 
> ..
> ResultSet rs2 = st.executeQuery("select 5::float8,asBinary('POINT(0
> 0)')");
> rs2.next();
> byte[] bs = rs2.getBytes(2);
> assertTrue(bs.length == 21);
> 
> The WKB representation of a 'POINT(0 0)' is 21 bytes long (1 byte for
> xdr/ndr flag, 4 bytes for type, and 2 8-byte doubles = 21 bytes).
> 
> If you step through the executeQuery() command in the postgresql driver,
> you'll eventually end up in PGStream#ReceiveTupleV3().  This is where
> the actual data is received from the database.
> 
> It clearly receives 84 bytes of data from the server.  This is the bytea
> text representation:
> \001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
> 
> The ResultSet#getBytes() function converts this to a byte[].
> 
> dave
> 
> 
> 
> 
> ----------------------------------------------------------
> This mail sent through IMP: https://webmail.limegroup.com/
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-22 18:39 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
@ 2005-02-23 14:57 ` Markus Schaber <schabios@logi-track.com>
  2005-02-24 09:39   ` [JDBC] [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Markus Schaber @ 2005-02-23 14:57 UTC (permalink / raw)

[X-Post to better place for discussion]

Hi, David,

dblasby at openplans.org schrieb:
> I was checking to see if the WKB (postgis 1.0) was actually transiting
> "in binary" from the server (postgresql 8) to a JDBC (also postgresql
> 8) client.
> 
> ..
> ResultSet rs2 = st.executeQuery("select 5::float8,asBinary('POINT(0 0)')");
> rs2.next();
> byte[] bs = rs2.getBytes(2);
> assertTrue(bs.length == 21);
> 
> The WKB representation of a 'POINT(0 0)' is 21 bytes long (1 byte for
> xdr/ndr flag, 4 bytes for type, and 2 8-byte doubles = 21 bytes).
> 
> If you step through the executeQuery() command in the postgresql driver,
> you'll eventually end up in PGStream#ReceiveTupleV3().  This is where
> the actual data is received from the database.
> 
> It clearly receives 84 bytes of data from the server.  This is the bytea
> text representation:
> \001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
> 
> The ResultSet#getBytes() function converts this to a byte[].

Maybe your postgresql driver only uses text transfer up to now.
asBinary() returns a byte array, so this should be transferred more
efficiently.

Can you try the following query:

select 5::float8,asBinary('POINT(0 0)')::bytea

Maybe the current 8.0-310 build has fixed this. But the pgsql-jdbc list
could be the better place to ask this question, IMHO, so I forward it to
there.


Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20050223/af2ad419/attachment.sig;



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [JDBC] [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-22 18:39 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
  2005-02-23 14:57 ` [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
@ 2005-02-24 09:39   ` Markus Schaber <schabios@logi-track.com>
  2005-02-24 10:32     ` [JDBC] [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Markus Schaber @ 2005-02-24 09:39 UTC (permalink / raw)

Hi, Kris,

Kris Jurka schrieb:

>>Maybe your postgresql driver only uses text transfer up to now.
>>asBinary() returns a byte array, so this should be transferred more
>>efficiently.
>
> The driver receives all data as text.  To be able to receive binary data 
> we must support binary data for all types because we do not know what type 
> we will be getting back from the SELECT before it is run.  Getting that 
> information would require an extra network round trip so we don't want to 
> do that.  Doing all binary transfer is on the 8.1 todo list, but I've yet 
> to really get started on it.

Oh, I thought that binary transmit was implemented in 8.0 :-(

Then, currently, the better way to receive geometries may be to use the
new canonical text rep for geometries (hex-encoded extended WKB) which
is only two times as large compared to pure binary rep.

As there are at least plans to use caching of prepared statements, it
also should be possible to cache this information together with the
prepared statement. This would reduce the number of roundtrips.

Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20050224/0d8c8c07/attachment.sig;



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [JDBC] [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-22 18:39 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
  2005-02-23 14:57 ` [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  2005-02-24 09:39   ` [JDBC] [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
@ 2005-02-24 10:32     ` Markus Schaber <schabios@logi-track.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Markus Schaber @ 2005-02-24 10:32 UTC (permalink / raw)

Hi, Kris,

Kris Jurka schrieb:

>>As there are at least plans to use caching of prepared statements, it
>>also should be possible to cache this information together with the
>>prepared statement. This would reduce the number of roundtrips.
> That's true, this information could be received on the first query or say 
> a PreparedStatement.getMetaData() call.  This would definitely be a 
> simpler thing to do, but still 8.1 material I think.

Yes, I agree that this is not material for 8.0.

Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20050224/8e2c0491/attachment.sig;



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
@ 2005-02-23 17:25 dblasby at openplans.org <dblasby@openplans.org>
  2005-02-23 17:32 ` [postgis-devel] JDBC & WKB - 400% overhead strk at refractions.net <strk@refractions.net>
  2005-02-23 17:35 ` [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  0 siblings, 2 replies; 10+ messages in thread

From: dblasby at openplans.org @ 2005-02-23 17:25 UTC (permalink / raw)

Markus,

>Maybe your postgresql driver only uses text transfer up to now.
>asBinary() returns a byte array, so this should be transferred more
>efficiently.

I'm using the JDBC3 build 310 drivers (latest from jdbc.postgresql.org).

>Can you try the following query:
>
>select 5::float8,asBinary('POINT(0 0)')::bytea
>
asBinary() already returns a bytea:

#\df asbinary
                     List of functions
 Schema |   Name   | Result data type | Argument data types
--------+----------+------------------+---------------------
 public | asbinary | bytea            | geometry
 public | asbinary | bytea            | geometry, text
(2 rows)

But, I tried your query and it, also, sends 84 bytes.

dave


----------------------------------------------------------
This mail sent through IMP: https://webmail.limegroup.com/




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-23 17:25 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
@ 2005-02-23 17:32 ` strk at refractions.net <strk@refractions.net>
  1 sibling, 0 replies; 10+ messages in thread

From: strk at refractions.net @ 2005-02-23 17:32 UTC (permalink / raw)

That's the way bytea is sent over ascii cursor.
If you can't get a binary cursor for whatever reason
you can use canonical output to obtain your HEXWKB form.
Be aware that canonical output actually returns HEXEWKB,
which is WKB extended with SRID, Z and M. To enforce an
OGC conformant WKB you need to setSRID(force_2d(geom), -1).

--strk;


On Wed, Feb 23, 2005 at 12:25:01PM -0500, dblasby at openplans.org wrote:
> Markus,
> 
> >Maybe your postgresql driver only uses text transfer up to now.
> >asBinary() returns a byte array, so this should be transferred more
> >efficiently.
> 
> I'm using the JDBC3 build 310 drivers (latest from jdbc.postgresql.org).
> 
> >Can you try the following query:
> >
> >select 5::float8,asBinary('POINT(0 0)')::bytea
> >
> asBinary() already returns a bytea:
> 
> #\df asbinary
>                      List of functions
>  Schema |   Name   | Result data type | Argument data types
> --------+----------+------------------+---------------------
>  public | asbinary | bytea            | geometry
>  public | asbinary | bytea            | geometry, text
> (2 rows)
> 
> But, I tried your query and it, also, sends 84 bytes.
> 
> dave
> 
> 
> ----------------------------------------------------------
> This mail sent through IMP: https://webmail.limegroup.com/
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-23 17:25 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
@ 2005-02-23 17:35 ` Markus Schaber <schabios@logi-track.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Markus Schaber @ 2005-02-23 17:35 UTC (permalink / raw)

Hi, David,

dblasby at openplans.org schrieb:

> asBinary() already returns a bytea:

Yes, I know that it should, but I just wanted to be shure. :-)

> But, I tried your query and it, also, sends 84 bytes.

Sad. But at least, we can be shure that it is a bytea specific problem
and not a PostGIS specific problem.

Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20050223/648ba1a0/attachment.sig;



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
@ 2005-02-23 19:18 dblasby at openplans.org <dblasby@openplans.org>
  2005-02-24 09:35 ` [postgis-devel] JDBC & WKB - 400% overhead Markus Schaber <schabios@logi-track.com>
  0 siblings, 1 reply; 10+ messages in thread

From: dblasby at openplans.org @ 2005-02-23 19:18 UTC (permalink / raw)

>Sad. But at least, we can be shure that it is a bytea specific problem
>and not a PostGIS specific problem.
>

Well - if you look at the ResultSet#getBytes() code, it explicity
decodes the "\000" format for columns of type bytea.

Perhaps using a Base64 encoding would be a good idea - its almost 3* as
efficient as this encoding (ie. 4 transfer bytes gives you 3 bytes of
actual data).

So, this is, fundamentally, a bytea problem.  Its really a SQL spec
problem since this is the defined behaviour for bytea transit - its
unlikely the case that Postgresql folks will change it.

But, its a postgis problem because its using bytea as the
representation.

Has anyone looked at just returning straight binary?  Postgresql
[usually] does not use cstrings (null terminated) - it uses pascal-like
strings (first 4 bytes are length, followed by byte data).  If you look
at the transit code, if you just write out straight binary, it should
be able to handle it.  Of course, you will no longer be able to use it
interactively because programs like psql will expect the output to be
cstrings.

dave




----------------------------------------------------------
This mail sent through IMP: https://webmail.limegroup.com/




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* [postgis-devel] JDBC & WKB - 400% overhead
  2005-02-23 19:18 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
@ 2005-02-24 09:35 ` Markus Schaber <schabios@logi-track.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Markus Schaber @ 2005-02-24 09:35 UTC (permalink / raw)

Hi, david,

dblasby at openplans.org schrieb:

> Well - if you look at the ResultSet#getBytes() code, it explicity
> decodes the "\000" format for columns of type bytea.
> 
> Perhaps using a Base64 encoding would be a good idea - its almost 3* as
> efficient as this encoding (ie. 4 transfer bytes gives you 3 bytes of
> actual data).

You can also use canonical text rep, this uses hex encoding.

Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios at logi-track.com | www.logi-track.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20050224/2d7763be/attachment.sig;



^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2005-02-24 10:32 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-22 18:39 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
2005-02-22 19:35 ` Paul Ramsey <pramsey@refractions.net>
2005-02-23 14:57 ` Markus Schaber <schabios@logi-track.com>
2005-02-24 09:39   ` Markus Schaber <schabios@logi-track.com>
2005-02-24 10:32     ` Markus Schaber <schabios@logi-track.com>
2005-02-23 17:25 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
2005-02-23 17:32 ` strk at refractions.net <strk@refractions.net>
2005-02-23 17:35 ` Markus Schaber <schabios@logi-track.com>
2005-02-23 19:18 [postgis-devel] JDBC & WKB - 400% overhead dblasby at openplans.org <dblasby@openplans.org>
2005-02-24 09:35 ` Markus Schaber <schabios@logi-track.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox