[PostGIS] #6155: Slow getClosestEdge

PostGIS trac at osgeo.org
Wed Nov 4 08:04:16 PST 2026


#6155: Slow getClosestEdge
--------------------------------+---------------------------
  Reporter:  Lars Aksel Opsahl  |      Owner:  strk
      Type:  defect             |     Status:  new
  Priority:  medium             |  Milestone:  PostGIS 3.7.1
 Component:  topology           |    Version:  3.6.x
Resolution:                     |   Keywords:
--------------------------------+---------------------------
Comment (by strk):

 The patch is fine, we don't need the edge_id sort if not for
 predictability of results in case of equidistant edges (mostly for
 testcases).

 When I try locally (PostgreSQL 17.11) I don't get a Gather Merge but this:
 {{{
  Limit  (cost=1.29..2.46 rows=1 width=12)
    ->  Incremental Sort  (cost=1.29..4869.27 rows=4150 width=12)
          Sort Key: ((edge_data.geom <->
 '0101000020A210000078966658E5CB2740A74EB847558A4F40'::geometry)),
 edge_data.edge_id
          Presorted Key: ((edge_data.geom <->
 '0101000020A210000078966658E5CB2740A74EB847558A4F40'::geometry))
          ->  Index Scan using edge_gist on edge_data  (cost=0.15..4682.52
 rows=4150 width=12)
                Order By: (geom <->
 '0101000020A210000078966658E5CB2740A74EB847558A4F40'::geometry)
 }}}


 Why that Gather Merge expects over 750k rows while only getting 1 instead
 I dunno. Did you run analyze before that query ? What version of
 PostgreSQL are you running this on ?
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/6155#comment:3>
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