<div dir="ltr"><div dir="ltr">To test your query I created a table using MobilityDB synthetic data generator as follows<br></div><div dir="ltr"><br></div><div dir="ltr">CREATE TABLE trips AS<br>SELECT k, random_tgeompointseq(1, 1000, 1, 1000, '2001-01-01', '2001-12-31', 10, 10, 1200, 1300) as trip<br>FROM generate_series(1, 17000) k;<br>-- SELECT 17000<br></div><div dir="ltr"><br></div><div dir="ltr">select SUM(numInstants(trip)) from trips;<br> 21 259 057<br></div><div dir="ltr"><br></div><div>This table has similar size as the one you described. In the first experiments there are no indices.</div><div><br></div><div>A query similar as yours is as follows</div><div><br></div><div>SELECT k as id, getTime(atvalue(tintersects(trip, geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))'
), true)) periods<br>FROM trips<br>WHERE intersects(trip, geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))'
);<br></div><div><br></div><div>Time: 5767.409 ms (00:05.767)<br></div><div><br></div><div>I tried an alternative version of your query (but this requires the latest version of MobilityDB in the develop branch)</div><div><br></div><div>
SELECT
k, getTime(atGeometry(trip, geometry 'Polygon((48 48,48 52,52 52, 52 48,48 48))')) </div><div>
FROM
trips </div><div>
WHERE
trip && geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))';<br></div><div><br></div><div>Time: 5432.174 ms (00:05.432)<br></div><div><br></div><div>With indices the queries run faster</div><div><br></div><div>CREATE INDEX trips_trip_spgist_idx ON trips USING spgist(trip);<br></div><div><br></div><div>SELECT k as id, getTime(atvalue(tintersects(trip, geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))'
), true)) periods<br>FROM trips<br>WHERE intersects(trip, geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))'
);</div><div> <br></div><div>Time: 3444.571 ms (00:03.445)<br></div><div><br></div><div><div>SELECT
k, getTime(atGeometry(trip, geometry 'Polygon((48 48,48 52,52 52, 52 48,48 48))')) </div><div>
FROM
trips </div><div>
WHERE
trip && geometry 'Polygon((48 48,48 52,52 52,52 48,48 48))';</div></div><div><br></div><div>Time: 3142.270 ms (00:03.142)<br></div><div><br></div><div>We are analyzing how to speed up these queries. I have run valgrind on them and 50 % of the execution time is spent in the calls to PostGIS in the tintersects query whereas it is 30% in the atGeometry query.</div><div><br></div><div>We will continue reflecting on this and let you know whether we were able to achieve some speed up.</div><div><br></div><div>Esteban</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>