[postgis-devel] TWKB_agg broken ?

Nicklas Avén nicklas.aven at jordogskog.no
Thu Aug 7 14:05:48 PDT 2014


On to., 2014-08-07 at 13:28 +0200, Nicklas Avén wrote:
> 
> 
> 
> 
> 
> 
> 2014-08-07 Sandro Santilli wrote:
> 
> On Thu, Aug 07, 2014 at 01:09:54PM +0200, Nicklas Avén wrote:
> >> Ah, Actually delta values will probabaly save you some space.
> >> 
> >> 
> >> The coordinates is saved as signed varInt. 1 byte only reaches from
> -64 to 63.
> >> 1 bit is lost in the varInt format signalizing if there is any more
> bytes
> >> And since it is signed another byte is lost on the positive side.
> >> 
> >> 
> >> So all values outside -64 - 63 will need 2 bytes in the
> ST_AsTWKB-version but in the agg version many of them will only use 1
> byte if the delta value to the point before per axis is between -64
> and 63
> >
> >Got it, but that's still a max of x2 size difference,
> >while we're talking about a x3 size difference here. 
> 
> 
> No, it actually makes perfectly sense :-)
> I didn't notice until now that all your points was that concentrated.
> 
> 
> This is what you will get 
> 
> 
> ST_AsTWKB per point
> header 1 byte
> type 1 byte
> coordinates 2x2 bytes (if 2d)
> 
> 
> ST_AsTWKBagg per point
> coordinates 2x1 bytes (your bbox tells there will be no delta values
> exceeding 1 byte limit)
> 
> 
> 
> 
> so, ST_AsTWKB will need 6 bytes per point and ST_AsTWKB will need 2
> bytes per point + 3 bytes for header, type and npoints in the begining
> 
> 
> If you use 5 decimals instead of 0 the difference will be much
> smaller.
> But the twkbagg version can be tuned by ordering the inputted
> geometries so they are statistically more close to each other.
> 
> 
> I have done some tests on real world data and I saved almost 30% by
> ordering on on of the axes like:
> 
> 
> SELECT ST_asTwkbAgg(geom, 5) from 
> (select geom from the_table order by ST_X(geom)) a;
> 
> 
> But that of course depends a lot of the data set. 
> 
> 
> /Nicklas
> 
> 


Now is the demo for aggregated twkb working again:

http://178.79.156.122/twkb_agg/

/Nicklas





More information about the postgis-devel mailing list