The problem I actually tried to solve was:
"Which ones streets may be associated to each populated place
within a 100 meters range ?"
More or less it seems quite the same of your original problem
involving pipes and customers.
===============================================================
First I tried a "raw" brutal force approach;
not using any Spatial Index at all
SELECT pp.Name, st.Name, Distance(pp.Geometry, st.Geometry)
FROM PopulatedPlaces AS pp, Streets AS st
WHERE Distance(pp.Geometry, st.Geometry) < 100.0
After waiting some 20 minutes I decided to kill SpatiaLite,
because it was quite obvious such a solution requires a long
time [and obviously, lots and lots of CPU cycles] to be computed.
--------------------
So I tried a "sophisticated" approach ...
I built an R*Tree Spatial Index for Streets.Geometry,
and then I executed the following SQL query:
SELECT pp.Name, st.Name, Distance(pp.Geometry, st.Geometry)
FROM PopulatedPlaces AS pp, Streets AS st
WHERE Distance(pp.Geometry, st.Geometry) < 100.0 AND st.ROWID IN
(
SELECT pkid FROM idx_Streets_Geometry
WHERE xmin < (MbrMaxX(pp.Geometry) + 100) AND
xmax > (MbrMinX(pp.Geometry) - 100) AND
ymin < (MbrMaxY(pp.Geometry) + 100) AND
ymax > (MbrMinY(pp.Geometry) - 100)
)
this time I was able to get a result set in about 1 minute;
and this is not at all surprising, because in this case I was
taking full profit from the R*Tree Spatial Index.
bye, Sandro