View Ticket
Not logged in
Ticket Hash: b087afbba52cc5795eb61002f7a87fac31eb26aa
Title: VirtualKnn wrong join result
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Resolution: Unable_To_Reproduce
Last Modified: 2017-04-20 15:35:00
Version Found In: 4.4.0 rc1
User Comments:
anonymous added on 2017-04-18 16:18:36:
Queries containing join with knn table don't return any result.
I've been using version 4.4.0 rc1 compiled with mingw64 6.3.0 on windows 10.

I created a new db from file http://download.geofabrik.de/europe/italy/sud-latest.osm.pbf:

spatialite_osm_net.exe -o sud-latest.osm.pbf -d sud-latest.osm.sqlite -T roads

Set the proper spatialindex:

select createspatialindex('roads', 'geometry');

The following query return 255484:

select fid
from knn k
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

but when we execute a join with the knn table no result is returned:

select *
from knn as k
join roads as r on (r.id = k.fid)
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

on the other hand the left join works as expected:

select *
from knn as k
left join roads as r on (r.id = k.fid)
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

roads|geometry||1|1|255484|8.88978575761523|255484|133033436|unclassified|77511|78050|Via Circolare PIP|1|1|339.638242679692|40.756589121563|



Le query che effettuano un join con la tabella knn non restituiscono alcun valore.

Sto usando la versione 4.4.0 rc1 compilata con mingw64 6.3.0 su windows 10.

Ho creato un db delle strade con il seguente comando partendo dal file http://download.geofabrik.de/europe/italy/sud-latest.osm.pbf:

spatialite_osm_net.exe -o sud-latest.osm.pbf -d sud-latest.osm.sqlite -T roads

Ho creato il seguente spatialindex:
select createspatialindex('roads', 'geometry');

La seguente query restituisce come valore 255484:

select fid
from knn k
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

Facendo una join con la tabella road non viene restituito nessun risultato:

select *
from knn as k
join roads as r on (r.id = k.fid)
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

Se invece viene utilizzata la left join allora si ottiene il risultato atteso:

select *
from knn as k
left join roads as r on (r.id = k.fid)
where k.f_table_name = 'roads' and k.ref_geometry = makepoint(14.147639, 42.418389) and max_items = 1;

roads|geometry||1|1|255484|8.88978575761523|255484|133033436|unclassified|77511|78050|Via Circolare PIP|1|1|339.638242679692|40.756589121563|

mj10777 added on 2017-04-19 06:23:58:

Following you sample, in building the database

    I cannot confirm that 'JOIN' statement does not work
I receive the expected results for all 3 queries.

On the 2016-12-10, corrections were made that resolve some problems
    but not all
      see: https://www.gaia-gis.it/fossil/libspatialite/tktview?name=56510318e2

Please check if your source is latter than 2016-12-10.


anonymous added on 2017-04-19 07:45:05:
version 4.4.0 rc1 is dated 09 may 2016.
What commited source code should i try?
Is the one listed in the following link ok?
https://www.gaia-gis.it/fossil/libspatialite/info/a02b6faf52997e3f

mj10777 added on 2017-04-19 13:21:53:

As a general rule, the latest commit should be used.
The date you used explains why it failed for you and worked for me.


anonymous added on 2017-04-20 15:35:00:
I compiled the last version (https://www.gaia-gis.it/fossil/libspatialite/info/714d644d04959bfe) and now all works as expected.

Thanks for your help.