2015-11-07 194 views
0

我正在使用Neo4j'neo4j-community-2.3.0-RC1'版本。 在我的數據庫中只有1054個節點。 當我使用'allShotestPaths'函數進行路徑查詢時,爲什麼它很慢。 它需要大約1秒以上,以下是單元測試結果:Neo4j:爲什麼allShortestPaths函數的性能如此之慢?

√ search optimalPath Path (192ms) 
    √ search optimal Path by Lat Lng (1131ms) 

我應該優化查詢?

MATCH path=allShortestPaths((start:濰坊_STATION)-[rels*..50]->(end:濰坊_STATION {name:"火車站"})) 
RETURN NODES(path) AS stations,relationships(path) AS path,length(path) AS stop_count, 
length(FILTER(index IN RANGE(1, length(rels)-1) WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
order by transfer_count,walk_count,stop_count 

由緯度LNG查詢最優路徑:對 'optimalPath' 和 '最佳路徑由緯度LNG'

optimalPath查詢以下是querys

MATCH path=allShortestPaths((start:濰坊_STATION {name:"公交總公司"})-[rels*..50]->(end:濰坊_STATION {name:"火車站"})) 
WHERE 
round(
6378.137 *1000*2* 
asin(sqrt(
    sin((radians(start.lat)-radians(36.714))/2)^2+cos(radians(start.lat))*cos(radians(36.714))* 
    sin((radians(start.lng)-radians(119.1268))/2)^2 
)) 
)/1000 < 0.5  // this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
RETURN NODES(path) AS stations,relationships(path) AS path,length(path) AS stop_count, 
length(FILTER(index IN RANGE(1, length(rels)-1) WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
order by transfer_count,walk_count,stop_count 

,你可以在這裏下載數據庫:https://www.dropbox.com/s/zamkyh2aaw3voe6/data.rar?dl=0

我會很感激,如果有人能幫助我。感謝

+0

您上傳的數據庫遺漏了大部分商店文件。 –

+0

你見過沙灘鞋的功能嗎? http://neo4j.com/docs/stable/query-functions-mathematical.html#functions-haversin –

+0

傳入的{lat}和{lon}參數是什麼? –

回答

1

一般情況下,不知道更多,我會拉的路徑都展開前可以計算的謂詞和表情,在比賽前。

而作爲您的地理過濾器是獨立的任何東西,除了你的參數和啓動節點否則,你可以這樣做:

MATCH (start:濰坊_STATION {name:"公交總公司"}) 

WHERE 
// this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
round(6378.137 *1000*2* 
     asin(sqrt(sin((radians(start.lat)-radians({lat}))/2)^2 
     +cos(radians(start.lat))*cos(radians({lat}))* 
     sin((radians(start.lng)-radians({lng}))/2)^2)))/1000 
< 0.5  

MATCH (end:濰坊_STATION {name:"火車站"}) 
MATCH path=allShortestPaths((start)-[rels*..50]->(end)) 
RETURN NODES(path) AS stations, 
     relationships(path) AS path, 
     length(path) AS stop_count, 
     length(FILTER(index IN RANGE(1, length(rels)-1) 
      WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
     length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 

ORDER BY transfer_count,walk_count,stop_count; 

看到這個測試(但其他查詢同樣快速):

neo4j-sh (?)$ MATCH (start:濰坊_STATION {name:"公交總公司"}) 
> 
> WHERE 
> // this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
> round(6378.137 *1000*2* 
>  asin(sqrt(sin((radians(start.lat)-radians({lat}))/2)^2 
>  +cos(radians(start.lat))*cos(radians({lat}))* 
>  sin((radians(start.lng)-radians({lng}))/2)^2)))/1000 
> < 0.5  
> 
> MATCH (end:濰坊_STATION {name:"火車站"}) 
> MATCH path=allShortestPaths((start)-[rels*..50]->(end)) 
> WITH NODES(path) AS stations, 
>  relationships(path) AS path, 
>  length(path) AS stop_count, 
>  length(FILTER(index IN RANGE(1, length(rels)-1) 
>    WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
>  length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
> 
> ORDER BY transfer_count,walk_count,stop_count 
> RETURN count(*); 
+----------+ 
| count(*) | 
+----------+ 
| 320  | 
+----------+ 
1 row 
10 ms 
+0

我上傳數據庫再次dropbox.com/s/zamkyh2aaw3voe6/data.rar?dl=0,我上傳整個「數據」文件夾,請檢查一下,非常感謝 – pangguoming

+0

抱歉,查詢的頂部,我必須刪除{name:「公交總公司」},它會匹配(開始:濰坊_STATION)WHERE ..............然後th電子查詢將花費超過1秒 – pangguoming

+0

我認爲,這是一個難題。非常感謝您的回覆 – pangguoming

相關問題