I have the
field_1 of my
Table_1 that must have the minimum distance between the geometry of my
Table_1 and any geometry of my
To do so, I used a
CROSS JOIN (Full Cartesian Product) between
Table_2. I also used the KNN operator
My trouble is that it took more than 3 hours to run and I decided to abort the query while it was running.
Here is my code:
UPDATE Table_1 SET field_1 = list.distance FROM( SELECT T1.gid AS name, MIN(T1.geom <-> T2.geom) AS distance FROM Table_1 AS T1 CROSS JOIN Table_2 AS T2 GROUP BY T1.gid ORDER BY T1.gid ) AS list WHERE Table_1.gid = list.name;
Do you have any ideas with a lighter query that could execute this much faster ? I already have created spatial indices.