[postgis-tickets] [PostGIS] #3731: SELECT * FROM testgeom WHERE ST_Intersects() and the back-end crashes

PostGIS trac at osgeo.org
Sun Mar 26 10:12:57 PDT 2017


#3731: SELECT * FROM testgeom WHERE ST_Intersects() and the back-end crashes
-------------------------------------------------+-------------------------
 Reporter:  zhuodao                              |      Owner:  pramsey
     Type:  defect                               |     Status:  new
 Priority:  medium                               |  Milestone:  PostGIS
                                                 |  2.1.9
Component:  postgis                              |    Version:  2.2.x
 Keywords:  ST_Intersects estimate_selectivity   |
  not a number                                   |
-------------------------------------------------+-------------------------
 I try to run some special sql as follow on PostgreSQL 9.4.10 and PostGis
 2.2.2 installed from source code, and the back-end crashes:

 {{{
  select the_geom from testgeom where
 ST_Intersects(the_geom,ST_GeomFromText( 'POLYGON((80.4748535
 32.2128011,80.4858398 32.2128011,80.4858398 32.2035053,80.4748535
 32.2035053,80.4748535 32.2128011))',4326));
 }}}

 The table testgeom contain a column of geometry TYPE like this:

 {{{
 gds=# \d testgeom;
   Column  |   Type   | Modifiers
 ----------+----------+-----------
          the_geom | geometry |
 }}}

 And it has three records.

 I get the backtrace:


 {{{
 #0  0x00007f081fca48a5 in raise () from /lib64/libc.so.6
 #1  0x00007f081fca6085 in abort () from /lib64/libc.so.6
 #2  0x00000000008f7e5e in ExceptionalCondition (
     conditionName=0xa86098 "!(rel->rows > 0 || ((rel)->cheapest_total_path
 != ((void *)0) && (((((const Node*)(((rel)->cheapest_total_path)))->type)
 == T_AppendPath) && ((AppendPath *)
 ((rel)->cheapest_total_path))->subpaths == "..., errorType=0xa8600b
 "FailedAssertion", fileName=0xa86000 "allpaths.c", lineNumber=350)
     at assert.c:54
 #3  0x00000000006d5930 in set_rel_size (root=0x2c6c138, rel=0x2c834c0,
 rti=5, rte=0x2c7bc60) at allpaths.c:350
 }}}

 I found rel->rows not a number and the divisor is zero in the
 gserialized_estimate.c:

 {{{
 cell_size[d] = (max[d] - min[d]) / nd_stats->size[d];
 }}}

 The nd_stats->size comes from the column stanumbersN table pg_statistic
 like this:

 {{{
 stanumbers1 |
 {2,0,0,0,0,80.4356,32.1458,0,0,80.5024,32.3317,0,0,7,7,7,7,1,7,7}
 }}}

 And I found function compute_gserialized_stats_mode  in the
 gserialized_estimate.c:1425

 {{{
 histo_cells_target = Min(histo_cells_target, (int)(total_rows/5));
 }}}

 When total_rows is greater than 0 and less than 5, histo_cells_target will
 be zero and it will cause the error.

 But I wonder why this histo_cells_target can be zero. Is it a bug ?

 And can I fix it as follow?

 {{{
 histo_cells_target = Min(histo_cells_target, Max(1, (int)(total_rows/5)));
 }}}

 By the way, run the same sql on the PostGis 2.1.7 and PostgreSQL 9.4.10
 return a right result.

--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/3731>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list