]> granicus.if.org Git - postgis/commitdiff
#2132, _postgis_stats crashes backend on missing stats
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 5 Dec 2012 18:50:42 +0000 (18:50 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 5 Dec 2012 18:50:42 +0000 (18:50 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10800 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/gserialized_estimate.c
regress/regress_selectivity.sql
regress/regress_selectivity_expected

index f1d3f957d6708116a793857652c9ec113534514a..7b8aa3c29296c0e7d4fcd472c2dda46462fbf00b 100644 (file)
@@ -1873,6 +1873,8 @@ estimate_selectivity(const GBOX *box, const ND_STATS *nd_stats, int mode)
 PG_FUNCTION_INFO_V1(_postgis_gserialized_stats);
 Datum _postgis_gserialized_stats(PG_FUNCTION_ARGS)
 {
+       Oid table_oid = PG_GETARG_OID(0);
+       text *att_text = PG_GETARG_TEXT_P(1);
        ND_STATS *nd_stats;
        char *str;
        text *json;
@@ -1883,7 +1885,11 @@ Datum _postgis_gserialized_stats(PG_FUNCTION_ARGS)
                mode = text_p_get_mode(PG_GETARG_TEXT_P(2));
 
        /* Retrieve the stats object */
-       nd_stats = pg_get_nd_stats_by_name(PG_GETARG_OID(0), PG_GETARG_TEXT_P(1), mode);
+       nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode);
+       if ( ! nd_stats )
+               elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
+               
+       /* Convert to JSON */
        str = nd_stats_to_json(nd_stats);
        json = cstring2text(str);
        pfree(str);
@@ -1915,7 +1921,7 @@ Datum _postgis_gserialized_sel(PG_FUNCTION_ARGS)
        nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode);
        
        if ( ! nd_stats )
-               elog(ERROR, "unable to load statistics! analyze?");
+               elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
 
        /* Calculate the gbox */
        if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
@@ -1951,8 +1957,11 @@ Datum _postgis_gserialized_joinsel(PG_FUNCTION_ARGS)
        nd_stats1 = pg_get_nd_stats_by_name(table_oid1, att_text1, mode);
        nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode);
 
-       if ( ! ( nd_stats1 && nd_stats2 ) ) 
-               elog(ERROR, "unable to load statistics! analyze?");
+       if ( ! nd_stats1 ) 
+               elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text2cstring(att_text1));
+
+       if ( ! nd_stats2 ) 
+               elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text2cstring(att_text2));
 
        /* Check if we've been asked to not use 2d mode */
        if ( ! PG_ARGISNULL(4) )
index ba3d63cd2c75334079efbf5150da3ed39e17d61f..6ea5f7bd3dc4e6fed51c666e2dd8a8e679a16446 100644 (file)
@@ -1,3 +1,16 @@
+
+-- Check for error messages
+create table no_stats ( g geometry, id integer );
+create table no_stats_join ( g geometry, id integer );
+select _postgis_selectivity('no_stats','g', 'LINESTRING(0 0, 1 1)');
+select _postgis_stats('no_stats','g');
+select _postgis_join_selectivity('no_stats', 'g', 'no_stats_join', 'g');
+insert into no_stats (g, id) values ('POINT(0 0)', 0);
+analyze no_stats;
+select _postgis_join_selectivity('no_stats', 'g', 'no_stats_join', 'g');
+drop table no_stats;
+drop table no_stats_join;
+
 -- Table with uniformly variable density, highest at 1,1, lowest at 10,10
 create table regular_overdots as
 with 
index 97acacc92ed18faa5421272c99b094d80eeaeabb..1ce2528499248d19c1dbcd21fbff5d1adaa8aeba 100644 (file)
@@ -1,3 +1,7 @@
+ERROR:  stats for "no_stats.g" do not exist
+ERROR:  stats for "no_stats.g" do not exist
+ERROR:  stats for "no_stats.g" do not exist
+ERROR:  stats for "no_stats_join.g" do not exist
 selectivity_00|2127
 selectivity_01|1068
 selectivity_02|actual|0.502