[postgis-devel] Updates to GEOS & POSTGIS

Tom Lane tgl at sss.pgh.pa.us
Fri Jan 18 20:09:45 PST 2008


Ben Jubb <benjubb at refractions.net> writes:
> The method I use to check the identity of the first geometry argument is 
> troublesome to me.  Right now, I do a memcmp() on the de-toasted 
> argument, and the previously stored argument in the cache.  This seems 
> like alot of work to me, but I having trouble coming up with a better 
> way.  One way that occured to me is to store the toasted data in the 
> cache instead, and do the comparison on the compressed data instead.  
> But is there a future-proof way to get the uncompressed data for the 
> datum?  Looks like I need to rip out the guts of toast_fetch_datum() to 
> do it.

I would *strongly* recommend not getting too familiar with the guts of
the toasting mechanism; that's one of the best ways to de-future-proof
your code that I can think of :-(

I don't really see anything much wrong with the memcmp idea, although
here are a few thoughts:

* memcmp is cheap as long as it hits a diff before proceeding real far.
You might want to organize the field order with malice aforethought
so that likely-to-be-different fields appear earlier.

* Be sure there are no uninitialized bits hiding anywhere in the struct,
like in padding bytes between fields.  If you make a practice of zeroing
the struct (eg with palloc0) before you fill the fields, this should be
okay.

* If you are dealing with float data then there's a small problem: zero
and minus zero are equal according to the IEEE spec, but not according
to memcmp.  I think you can probably ignore this for the case of
deciding whether a cache entry is still valid, since a phony "not equal"
indication is at worst a performance hit not a correctness problem.
But it's something to keep at the back of your head.

			regards, tom lane



More information about the postgis-devel mailing list