我努力优化以下查询,但无法将其降低到两分钟以下 - 这是预期的吗?有什么方法可以加快速度。我添加了索引并尽可能使用WITH
。
match (md:MarketingDetail {Status: 'Live'})
with md limit 10
match (md) -[:Has_Area]-> (a:Area)
with md, a
match (ss:SavedSearch) -[:Has_Area]->(a)
with md, ss match
(md) -[:Has_Trade] -> (st:SectorTrade) <-[:Has_Trade]- (ss)
where ((md.FreeholdTenure ='Freehold'
and ss.FreeholdTenure = 'true'
and (md.FreeholdSearchPrice >= ss.PriceFrom
or md.FreeholdSearchPrice is null)
and (md.FreeholdSearchPrice <= ss.PriceTo
or md.FreeholdSearchPrice is null))
or (md.LeaseholdTenure is not null
and ss.LeaseholdTenure = 'true'
and (md.LeaseholdSearchPrice >= ss.PriceFrom
or md.LeaseholdSearchPrice is null)
and (md.LeaseholdSearchPrice <= ss.PriceTo
or md.LeaseholdSearchPrice is null)))
return count(ss)
以下是上述查询的个人资料 -
谢谢!
答案 0 :(得分:0)
在不了解您的图表及其结构/大小的情况下,很难确切知道如何有效地查询它。在查询所需模式之前,您的查询似乎与每个md
和ss
组合相匹配,根据图表,这可能是也可能不是最好的方法,但我已尝试过替代下面。
您可以在查询之前放置PROFILE
以查看其执行方式并查找瓶颈。您可以通过运行:schema
??
MATCH (md:MarketingDetail {Status: 'Live'})
WHERE
(
md.FreeholdTenure ='Freehold'
OR md.LeaseholdTenure is not null
OR md.LeaseholdSearchPrice is null
OR md.LeaseholdSearchPrice is null
)
WITH md LIMIT 10
match (md) -[:Has_Area]-> (a:Area)<-[:Has_Area]-(ss:SavedSearch)-[:Has_Trade]->(st:SectorTrade)-[:Has_Trade]->(md)
where
AND
(
md.FreeholdTenure ='Freehold'
and ss.FreeholdTenure = 'true'
and (md.FreeholdSearchPrice >= ss.PriceFrom or md.FreeholdSearchPrice is null)
and (md.FreeholdSearchPrice <= ss.PriceTo or md.FreeholdSearchPrice is null)
)
or (
md.LeaseholdTenure is not null
and ss.LeaseholdTenure = 'true'
and (
md.LeaseholdSearchPrice >= ss.PriceFrom
or md.LeaseholdSearchPrice is null
)
and (
md.LeaseholdSearchPrice <= ss.PriceTo
or md.LeaseholdSearchPrice is null
)
)
return count(ss)
答案 1 :(得分:0)
根据您的PROFILE
,您没有:MarketingDetail(Status)
的索引,这对您的查询非常重要,因为第一个MATCH
需要这个索引。
此外,重构您的查询(可能以@DonWeldon建议的方式)应该会有所帮助。