[postgis-devel] Alignment Revision

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Wed Jan 21 02:38:03 PST 2009


Paul Ramsey wrote:

> I wonder if I should put this document into SVN? We could start an RFC 
> directory for these kinds of discussions. Things like your performance 
> testing, Mark, shouldn't be hidden in the mail archive.
> 
> (This revision adds two examples for single-part multilinestrings, which 
> shows one of the downsides of including a "user-data" 4-byte block at 
> the start of the structure. Might be better to just pad the PG_LWGEOM an 
> extra four bytes forward (but then you pay in the simple point case).)

Nice work Paul. On skim-reading the document, it looks reasonably 
sensible although I'll have to sit down and read it in some detail. 
However, I think that your fundamental statement about LWGEOM is wrong:

'Right now, PG_LWGEOM is just an LWGEOM with an extra 4-bytes of 
information tacked onto the front.'

This is not true. A LWGEOM structure contains the basics about the 
geometry, but does not contain any coordinate information. Think about a 
LWLINE which contains a pointer to a POINTARRAY which itself points to 
an array of doubles which can be anywhere in memory.

In order to get the LWGEOM in/out of PostgreSQL we need to 
serialize/deserialize the geometry. So what we are handed by PostgreSQL 
is actually a *SERIALIZED* LWGEOM and so we must deserialize it into a 
LWGEOM structure that we can actually do something useful with. The most 
interesting part about this is that during the opposite process of 
serialization, we have to iterate through any point arrays within a 
LWGEOM anyway in order to memcpy() them into serialized form ready to 
return to PostgreSQL.

Copying the minimal amount of information from the head of a serialized 
LWGEOM to a LWGEOM will be extremely quick, and so I'm not worried about 
this. Therefore the key is to make the coordinate arrays double-aligned 
within the PostgreSQL Datum so that during the deserialization process, 
we can just point the POINTARRAY straight into the Datum - which is what 
already happens.

Hence all we have to do is:

	- Ensure the double arrays are aligned within the Datum
	- Rewrite any accessor methods to iterate through the
	array pointer directly, rather than through
	getPoint_internal

I'll have a read through the proposed schemes in more detail when I get 
a spare moment :O


HTH,

Mark.

-- 
Mark Cave-Ayland
Sirius Corporation - The Open Source Experts
http://www.siriusit.co.uk
T: +44 870 608 0063



More information about the postgis-devel mailing list