create table wtemp
as
select smp.simple_id,smp.slink,lau.lau_name
from smp
left join
lau
on st_coveredby(smp.shape,lau.shape)=1
where smp.rowid in
(select rowid from spatialindex where f_table_name='smp' and search_frame=lau.shape)
W/o index
0 0 1 SCAN TABLE simpplle_attributes AS sa
0 1 0 SEARCH TABLE slink_lu AS slu USING INDEX slu_slink_idx (slink=?)
0 2 2 SEARCH TABLE gis_data AS g USING INDEX gis_data_simpleid_idx (SIMPLE_ID=?)
0 3 3 SCAN TABLE lau
w/ index
0 0 1 SCAN TABLE simpplle_attributes AS sa
0 1 0 SEARCH TABLE slink_lu AS slu USING INDEX slu_slink_idx (slink=?)
0 2 2 SEARCH TABLE gis_data AS g USING INDEX gis_data_simpleid_idx (SIMPLE_ID=?)
0 3 3 SCAN TABLE lau
0 0 0 EXECUTE CORRELATED LIST SUBQUERY 1
1 0 0 SCAN TABLE spatialindex VIRTUAL TABLE INDEX 2
CREATE VIEW smp AS
SELECT g.rowid AS rowid,
slu.simple_id AS simple_id,
slu.slink AS slink,
g.shape AS shape
FROM slink_lu slu,
simpplle_attributes sa,
gis_data g
WHERE g.simple_id = slu.simple_id AND
slu.slink = sa.slink AND
sa.ownership = 'NF-OTHER';
Details. The gis_data table has a spatial index, the spatial view has the index registered like so.
smp shape rowid gis_data shape 1
select smp.simple_id,lau.lau_name
from gis_data smp
left join
lau
on st_coveredby
(smp.shape,lau.shape)=1
where
smp.rowid in
(select rowid from spatialindex where f_table_name='gis_data' and search_frame=lau.shape)
and did not see any difference in speed.
select smp.simple_id,smp.slink,lau.lau_name
from
smp
left join
lau
on st_coveredby
(smp.shape,lau.shape)=1
where lau.rowid in
(select rowid from spatialindex where f_table_name='lau' and search_frame=smp.shape)
cut the time down to 72 seconds. Which is better but not the level of improvement that I was hoping to get.
One thought I had is the complexity of the search, ie the geometry from the lau table is complex. I did something similar to your reply (http://www.gaia-gis.it/spatialite-3.0.0-BETA1/WorldBorders.pdf) in this thread https://groups.google.com/forum/#!searchin/spatialite-users/index/spatialite-users/hV43tQPnPgo/SBnO8cJd7PIJ.
using the newer squaregrid and elementarygeometries functions to create the simpler geometry version of the lau layer.
The final join query ran quicker, about 38 seconds but there was some time, about 10 seconds, in generating the grid.
Just quick comment about the query itself. It is a left join for a reason, as the query shown here is really a subquery for a query that groups by the lau_name field. Doing the left join instead of an inner join only adds a few seconds to the query.
David