Fix selectivity estimation @> (anymultirange, anyrange) operator
authorAlexander Korotkov <[email protected]>
Wed, 30 Dec 2020 17:19:15 +0000 (20:19 +0300)
committerAlexander Korotkov <[email protected]>
Wed, 30 Dec 2020 17:31:15 +0000 (20:31 +0300)
Attempt to get selectivity estimation for @> (anymultirange, anyrange) operator
caused an error in buildfarm, because this operator was missed in switch()
of calc_hist_selectivity().  Fix that and also make regression tests reliably
check that selectivity estimation for (multi)ranges doesn't fall.  Previously,
whether we test selectivity estimation for (multi)ranges depended on
whether autovacuum managed to gather concurrently to the test.

Reported-by: Michael Paquier
Discussion: https://postgr.es/m/X%2BwmgjRItuvHNBeV%40paquier.xyz

src/backend/utils/adt/multirangetypes_selfuncs.c
src/test/regress/expected/multirangetypes.out
src/test/regress/expected/rangetypes.out
src/test/regress/sql/multirangetypes.sql
src/test/regress/sql/rangetypes.sql

index bb016b6e9877062038e1e68d21ea7e6d0b7455ae..14283e4503a2b8aa1ff3219204434ab947837ea6 100644 (file)
@@ -649,6 +649,7 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
 
        case OID_MULTIRANGE_RANGE_CONTAINED_OP:
        case OID_MULTIRANGE_MULTIRANGE_CONTAINED_OP:
+       case OID_RANGE_MULTIRANGE_CONTAINED_OP:
            if (const_lower.infinite)
            {
                /*
index 86011a02a1e69d1fee425d46df96af645890631f..04953a599032449dc8c7cb5b0b5e7a84b5da5b41 100644 (file)
@@ -2227,6 +2227,11 @@ insert into test_multirange_gist select int4multirange(int4range(g, g+10000)) fr
 insert into test_multirange_gist select int4multirange(int4range(NULL, g*10, '(]'), int4range(g*10, g*20, '(]')) from generate_series(1,100) g;
 insert into test_multirange_gist select int4multirange(int4range(g*10, g*20, '(]'), int4range(g*20, NULL, '(]')) from generate_series(1,100) g;
 create index test_mulrirange_gist_idx on test_multirange_gist using gist (mr);
+-- test statistics and selectivity estimation as well
+--
+-- We don't check the accuracy of selectivity estimation, but at least check
+-- it doesn't fall.
+analyze test_multirange_gist;
 -- first, verify non-indexed results
 SET enable_seqscan    = t;
 SET enable_indexscan  = f;
index 28dc995e5994fa4552884f14e86cd6a92809249d..05b882fde93f30b0ef62ce2f65bbd46ab1ac9ef0 100644 (file)
@@ -792,6 +792,11 @@ insert into test_range_gist select 'empty'::int4range from generate_series(1,500
 insert into test_range_gist select int4range(NULL,g*10,'(]') from generate_series(1,100) g;
 insert into test_range_gist select int4range(g*10,NULL,'(]') from generate_series(1,100) g;
 insert into test_range_gist select int4range(g, g+10) from generate_series(1,2000) g;
+-- test statistics and selectivity estimation as well
+--
+-- We don't check the accuracy of selectivity estimation, but at least check
+-- it doesn't fall.
+analyze test_range_gist;
 -- first, verify non-indexed results
 SET enable_seqscan    = t;
 SET enable_indexscan  = f;
index 2a2ee4dcdfd8fe70989d67df0e32880301e6708a..692f2416d9b8d93279074a5afc790202b2a4da35 100644 (file)
@@ -423,6 +423,12 @@ insert into test_multirange_gist select int4multirange(int4range(NULL, g*10, '(]
 insert into test_multirange_gist select int4multirange(int4range(g*10, g*20, '(]'), int4range(g*20, NULL, '(]')) from generate_series(1,100) g;
 create index test_mulrirange_gist_idx on test_multirange_gist using gist (mr);
 
+-- test statistics and selectivity estimation as well
+--
+-- We don't check the accuracy of selectivity estimation, but at least check
+-- it doesn't fall.
+analyze test_multirange_gist;
+
 -- first, verify non-indexed results
 SET enable_seqscan    = t;
 SET enable_indexscan  = f;
index 51eddabf60f4e46266fa977d33b11bb4eb44fb9f..e1b8917c0c538bf95b1e2f8d51be2a8b62a198af 100644 (file)
@@ -216,6 +216,12 @@ insert into test_range_gist select int4range(NULL,g*10,'(]') from generate_serie
 insert into test_range_gist select int4range(g*10,NULL,'(]') from generate_series(1,100) g;
 insert into test_range_gist select int4range(g, g+10) from generate_series(1,2000) g;
 
+-- test statistics and selectivity estimation as well
+--
+-- We don't check the accuracy of selectivity estimation, but at least check
+-- it doesn't fall.
+analyze test_range_gist;
+
 -- first, verify non-indexed results
 SET enable_seqscan    = t;
 SET enable_indexscan  = f;