[postgis-devel] Avoid unnecessary memory copy in gserialized_datum_get_box2df_p

Sandro Santilli strk at keybit.net
Tue Oct 1 09:12:13 PDT 2013


Hi Yuto,

On Wed, Oct 02, 2013 at 12:49:18AM +0900, Yuto HAYAMIZU wrote:
> Hi,
> 
> This is my first post to postgis-devel ML, and I attached a small
> performance improvement patch.
> In gserialized_datum_get_box2df_p, PG_DETOAST_DATUM_SLICE is always called
> for obtaining header section of the gserialized datum.
> PG_DETOAST_DATUM_SLICE always performs memory allocation and copy, but
> such memory operations are not necessary when the datum is not extended(
> not external nor compressed ).
> This patch removes such extra memory operations by just calling
> PG_DETOAST_DATUM.
> It can be applied to svn trunk and 2.0 branch. I have confirmed all
> regression tests are passed with PostgreSQL 9.2.4.
> 
> I observed 11% performance improvement with a certain dataset.
> Unfortunately details of the dataset cannot be disclosed, but it consists
> of a table containing 10M records with a GiST-indexed geometry column and
> a table containing polygons.
> Tested query is like: SELECT count(*) FROM polygons, points WHERE
> polygons.attr = XXX AND ST_Within(points.the_geom, polygons.the_geom);
> 
> Any thoughts?

good catch !

So is PG_DETOAST_DATUM a no-op for non-external and non-compressed
values ?

The only other use of PG_DETOAST_DATUM_SLICE is in ST_IsCollection,
may be worth fixing that too.

Have you profiled other geometry types or postgresql version ?

--strk;



More information about the postgis-devel mailing list