]> granicus.if.org Git - postgis/commitdiff
Fix the geography <column> && <column> selectivity code. Now the answers between...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Fri, 16 Oct 2009 16:33:22 +0000 (16:33 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Fri, 16 Oct 2009 16:33:22 +0000 (16:33 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4660 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography_estimate.c

index 531adfd82bc16c608d0d24135fe3acdd318c01e0..3d1f33d18c4e29003b9f4623ffdc6dbedd506d67 100644 (file)
@@ -90,6 +90,9 @@ typedef struct GEOG_STATS_T
        /* histogram extent */
        float4 xmin, ymin, zmin, xmax, ymax, zmax;
 
+       /* No. of geometries within this column (approx) */
+       float4 totalrows;
+
        /*
         * variable length # of floats for histogram
         */
@@ -705,26 +708,21 @@ Datum geography_gist_join_selectivity(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUGF(3, "selectivity1: %.15g   selectivity2: %.15g", selectivity1, selectivity2);
 
-       /* Free the statistic tuples */
-       free_attstatsslot(0, NULL, 0, (float *)geogstats1, geogstats1_nvalues);
-       ReleaseSysCache(stats1_tuple);
-
-       free_attstatsslot(0, NULL, 0, (float *)geogstats2, geogstats2_nvalues);
-       ReleaseSysCache(stats2_tuple);
-
        /*
        * OK, so before we calculate the join selectivity we also need to
        * know the number of tuples in each of the columns since
        * estimate_selectivity returns the number of estimated tuples
-       * divided by the total number of tuples. Fortunately we can work
-       * this out by multiplying the average features per cell by the
-       * number of cells.
+       * divided by the total number of tuples.
        */
-       num1_tuples = geogstats1->avgFeatureCells * geogstats1->unitsx * geogstats1->unitsy *
-                       geogstats1->unitsz;
+       num1_tuples = geogstats1->totalrows;
+       num2_tuples = geogstats2->totalrows;
 
-       num2_tuples = geogstats2->avgFeatureCells * geogstats2->unitsx * geogstats2->unitsy *
-                       geogstats2->unitsz;
+       /* Free the statistic tuples */
+       free_attstatsslot(0, NULL, 0, (float *)geogstats1, geogstats1_nvalues);
+       ReleaseSysCache(stats1_tuple);
+
+       free_attstatsslot(0, NULL, 0, (float *)geogstats2, geogstats2_nvalues);
+       ReleaseSysCache(stats2_tuple);
 
        /*
        * Finally calculate the estimate of the number of rows returned
@@ -1251,6 +1249,7 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
        geogstats->unitsx = unitsx;
        geogstats->unitsy = unitsy;
        geogstats->unitsz = unitsz;
+       geogstats->totalrows = totalrows;
 
        /* Initialize all values to 0 */
        for (i = 0; i < histocells; i++)