【问题标题】:NEO4J Cypher query slowNEO4J Cypher 查询速度慢
【发布时间】:2018-06-18 11:12:03
【问题描述】:

我已努力优化以下查询,但无法将其缩短到两分钟以下 - 这是预期的吗?有什么办法可以加快速度。我已添加索引并尽可能使用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)

这是上述查询的简介 -

谢谢!

【问题讨论】:

  • 您能分享您的 PROFILE 输出(展开所有框并分享屏幕截图)吗?第一个之后不需要 WITH 语句。
  • 我已将 PROFILE 的结果添加到上述问题中 - 谢谢!

标签: neo4j cypher


【解决方案1】:

在不了解您的图表及其结构/大小的情况下,很难确切知道如何有效地查询它。目前,在查询所需模式之前,您的查询似乎与每个 mdss 组合匹配,这可能是也可能不是最佳方法,具体取决于图表,但我尝试了下面的替代方法。

您可以将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)

【讨论】:

    【解决方案2】:

    根据您的PROFILE,您没有:MarketingDetail(Status) 的索引,这对于您的查询非常重要,因为第一个MATCH 需要它。

    此外,重组您的查询(可能以@DonWeldon 建议的方式)应该会有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 2015-11-01
      • 2017-12-24
      • 1970-01-01
      相关资源
      最近更新 更多