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);
}
(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);
}
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);
}
(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);
}
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);
}
* 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)
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);
/**********************************************************************
* $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
*