I'm trying to speed up a query in a virtual layer. I noticed that the query runs at the same time for a partial extension and full extent of the layer shown on the map. So I thought if I filtered the query for the canvas extension I would gain an acceleration in performance.
I thought of something like this but don't know if is possible:
SELECT s.id AS id, s.codigo AS codigo, s.geometry AS geometry, SUM(d.e1) AS sum1, SUM(d.e2) AS sum2, SUM(d.e3) AS sum3, SUM(d.e4) AS sum4, SUM(d.e5) AS sum5, DT_atu AS DT_atu FROM "lyr1" AS s, "lyr2" AS d WHERE d._search_frame_ = s.geometry AND ST_WITHIN(d.geometry, s.geometry) AND ST_WITHIN(s.geometry, iface.mapCanvas()) GROUP BY s.id;