OpenRailAssociation / osrd

An open source web application for railway infrastructure design, capacity analysis, timetabling and simulation
https://osrd.fr
GNU Lesser General Public License v3.0
430 stars 40 forks source link

Create an efficient index for tile creation #3297

Open bloussou opened 1 year ago

bloussou commented 1 year ago

Description and goal

Spotted by @multun :

Currently django is creating automatically a spatial index. We should try spatial_index=False when creating geographic fields in django and add manually a composite gist on (infra_id, geographic)

Acceptance criteria

Request should be faster:

multun commented 1 year ago

I ran some tests and figure out that postgres indeed uses indexes when the bbox is small enough. it is smart enough to figure out that it needs all the data anyway to serialize everything

multun commented 1 year ago

For example, this works fine:

 WITH bbox AS (
     SELECT TileBBox(15, 16562, 11421, 3857) AS geom
 )
 SELECT ST_AsGeoJson(geographic) AS geom,
     track_section.data AS data
 FROM osrd_infra_tracksectionlayer layer
     CROSS JOIN bbox
     inner join osrd_infra_tracksectionmodel track_section on track_section.obj_id = layer.obj_id
     and track_section.infra_id = layer.infra_id
 WHERE layer.infra_id = 1
     AND geographic && bbox.geom
     AND ST_GeometryType(geographic) != 'ST_GeometryCollection'