]> granicus.if.org Git - postgis/commitdiff
Be (slightly) more memory friendly when generating statistics
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 4 Mar 2015 19:49:36 +0000 (19:49 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 4 Mar 2015 19:49:36 +0000 (19:49 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13303 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/gserialized_estimate.c

index 4d2e187f84e85b391522dbfabab288d1ea00228b..a8829a837b1ebf8c015d7187f7d50d9b84d593a7 100644 (file)
@@ -1299,6 +1299,7 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu
                GBOX gbox;
                ND_BOX *nd_box;
                bool is_null;
+               bool is_copy;
 
                datum = fetchfunc(stats, i, &is_null);
 
@@ -1312,6 +1313,7 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu
                        
                /* Read the bounds from the gserialized. */
                geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
+               is_copy = VARATT_IS_EXTENDED(datum);
                if ( LW_FAILURE == gserialized_get_gbox_p(geom, &gbox) )
                {
                        /* Skip empties too. */
@@ -1363,6 +1365,10 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu
 
                /* Increment our "good feature" count */
                notnull_cnt++;
+               
+               /* Free up memory if our sample geometry was copied */
+               if ( is_copy ) 
+                       pfree(geom);
 
                /* Give backend a chance of interrupting us */
                vacuum_delay_point();