From: Sandro Santilli Date: Mon, 18 Apr 2005 10:57:13 +0000 (+0000) Subject: Applied patched by Ron Mayer fixing memory leakages and invalid results X-Git-Tag: pgis_1_1_0~427 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e7021292f85fd5a356c65ac95f2e04b55ec0f8c;p=postgis Applied patched by Ron Mayer fixing memory leakages and invalid results in join selectivity estimator. Fixed some return to use default JOIN selectivity estimate instead of default RESTRICT selectivity estimate. git-svn-id: http://svn.osgeo.org/postgis/trunk@1629 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom_estimate.c b/lwgeom/lwgeom_estimate.c index 55ded4a16..f47259211 100644 --- a/lwgeom/lwgeom_estimate.c +++ b/lwgeom/lwgeom_estimate.c @@ -841,9 +841,9 @@ Datum LWGEOM_gist_joinsel(PG_FUNCTION_ARGS) if ( ! stats1_tuple ) { #if DEBUG_GEOMETRY_STATS - elog(NOTICE, " No statistics, returning default estimate"); + elog(NOTICE, " No statistics, returning default geometry join selectivity"); #endif - PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_SEL); + PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_JOINSEL); } @@ -853,10 +853,10 @@ Datum LWGEOM_gist_joinsel(PG_FUNCTION_ARGS) (float4 **)&geomstats1, &geomstats1_nvalues) ) { #if DEBUG_GEOMETRY_STATS - elog(NOTICE, " STATISTIC_KIND_GEOMETRY stats not found - returning default geometry selectivity"); + elog(NOTICE, " STATISTIC_KIND_GEOMETRY stats not found - returning default geometry join selectivity"); #endif ReleaseSysCache(stats1_tuple); - PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_SEL); + PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_JOINSEL); } @@ -865,9 +865,12 @@ Datum LWGEOM_gist_joinsel(PG_FUNCTION_ARGS) if ( ! stats2_tuple ) { #if DEBUG_GEOMETRY_STATS - elog(NOTICE, " No statistics, returning default estimate"); + elog(NOTICE, " No statistics, returning default geometry join selectivity"); #endif - PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_SEL); + free_attstatsslot(0, NULL, 0, (float *)geomstats1, + geomstats1_nvalues); + ReleaseSysCache(stats1_tuple); + PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_JOINSEL); } @@ -876,10 +879,13 @@ Datum LWGEOM_gist_joinsel(PG_FUNCTION_ARGS) (float4 **)&geomstats2, &geomstats2_nvalues) ) { #if DEBUG_GEOMETRY_STATS - elog(NOTICE, " STATISTIC_KIND_GEOMETRY stats not found - returning default geometry selectivity"); + elog(NOTICE, " STATISTIC_KIND_GEOMETRY stats not found - returning default geometry join selectivity"); #endif + free_attstatsslot(0, NULL, 0, (float *)geomstats1, + geomstats1_nvalues); ReleaseSysCache(stats2_tuple); - PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_SEL); + ReleaseSysCache(stats1_tuple); + PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_JOINSEL); } @@ -963,6 +969,21 @@ Datum LWGEOM_gist_joinsel(PG_FUNCTION_ARGS) elog(NOTICE, "Estimated rows returned: %f", rows_returned); #endif + /* + * One (or both) tuple count is zero... + * We return default selectivity estimate. + * We could probably attempt at an estimate + * w/out looking at tables tuple count, with + * a function of selectivity1, selectivity2. + */ + if ( ! total_tuples ) + { +#if DEBUG_GEOMETRY_STATS + elog(NOTICE, "Total tuples == 0, returning default join selectivity"); +#endif + PG_RETURN_FLOAT8(DEFAULT_GEOMETRY_JOINSEL); + } + PG_RETURN_FLOAT8(rows_returned / total_tuples); } @@ -1329,7 +1350,9 @@ Datum LWGEOM_estimated_extent(PG_FUNCTION_ARGS) * of a search_box looking at data in the GEOM_STATS * structure. * - * TODO: handle box dimension collapses + * TODO: handle box dimension collapses (probably should be handled + * by the statistic generator, avoiding GEOM_STATS with collapsed + * dimensions) */ static float8 estimate_selectivity(BOX2DFLOAT4 *box, GEOM_STATS *geomstats) @@ -1381,6 +1404,11 @@ estimate_selectivity(BOX2DFLOAT4 *box, GEOM_STATS *geomstats) histocols = geomstats->cols; historows = geomstats->rows; +#if DEBUG_GEOMETRY_STATS + elog(NOTICE, " histogram has %d cols, %d rows", histocols, historows); + elog(NOTICE, " histogram geosize is %fx%f", geow, geoh); +#endif + cell_area = (geow*geoh) / (histocols*historows); //box_area = (box->high.x-box->low.x)*(box->high.y-box->low.y); box_area = (box->xmax-box->xmin)*(box->ymax-box->ymin); @@ -2454,6 +2482,11 @@ Datum LWGEOM_estimated_extent(PG_FUNCTION_ARGS) /********************************************************************** * $Log$ + * Revision 1.30 2005/04/18 10:57:13 strk + * Applied patched by Ron Mayer fixing memory leakages and invalid results + * in join selectivity estimator. Fixed some return to use default JOIN + * selectivity estimate instead of default RESTRICT selectivity estimate. + * * Revision 1.29 2005/03/25 09:34:25 strk * code cleanup *