]> granicus.if.org Git - postgis/commitdiff
Add test for selectivity estimator
authorSandro Santilli <strk@keybit.net>
Mon, 21 Jul 2014 16:12:40 +0000 (16:12 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 21 Jul 2014 16:12:40 +0000 (16:12 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@12813 b70326c6-7e19-0410-871a-916f4a2858ee

regress/regress_index.sql
regress/regress_index_expected

index 8b51160c32563e5935c31b017da3e2e348bd8f33..6cd666779ba480de4d3983299913b35af27f1229 100644 (file)
@@ -13,4 +13,58 @@ set enable_seqscan = off;
 
  select num,ST_astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d  order by num;
 
+CREATE FUNCTION estimate_error(qry text, tol int)
+RETURNS text
+LANGUAGE 'plpgsql' VOLATILE AS $$
+DECLARE
+  anl XML; -- analisys
+  err INT; -- absolute difference between planned and actual rows
+  est INT; -- estimated count
+  act INT; -- actual count
+BEGIN
+  EXECUTE 'EXPLAIN (ANALYZE, FORMAT XML) ' || qry INTO STRICT anl;
+
+  SELECT (xpath('//x:Plan-Rows/text()', anl,
+         ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]))[1]
+         ::text::int
+  INTO est;
+
+  SELECT (xpath('//x:Actual-Rows/text()', anl,
+         ARRAY[ARRAY['x', 'http://www.postgresql.org/2009/explain']]))[1]
+         ::text::int
+  INTO act;
+
+  err = abs(est-act);
+
+  RETURN act || '+=' || tol || ':' || coalesce(
+    nullif((err < tol)::text,'false'),
+    'false:'||err::text
+    );
+
+END;
+$$;
+
+-- There are 50000 points in the table with full extent being
+-- BOX(0.0439142361 0.0197799355,999.955261 999.993652)
+
+ANALYZE test;
+
+SELECT estimate_error('
+ select num from test where the_geom && ST_MakeEnvelope(125,125,135,135);
+', 5);
+
+select estimate_error('
+ select num from test where the_geom && ST_MakeEnvelope(0,0,135,135);
+', 50);
+
+SELECT estimate_error('
+ select num from test where the_geom && ST_MakeEnvelope(0,0,500,500);
+', 500);
+
+SELECT estimate_error('
+ select num from test where the_geom && ST_MakeEnvelope(0,0,1000,1000);
+', 600);
+
 DROP TABLE test;
+
+DROP FUNCTION estimate_error(text, int);
index 19dc436cfc6fd270b76c01b3bd4fd015feef1126..035aa0f3d05f3607ca0aeec21431355d79b55b37 100644 (file)
@@ -4,3 +4,7 @@
 2594|POINT(130.504303 126.53112)
 3618|POINT(130.447205 131.655289)
 7245|POINT(128.10466 130.94133)
+3+=5:true
+924+=50:true
+12621+=500:true
+50000+=600:true