代码之家  ›  专栏  ›  技术社区  ›  Gqueee

每次查询的执行时间

  •  0
  • Gqueee  · 技术社区  · 2 年前

    在第y列中,我想返回查询序列号。我知道这是不对的,但我不知道我该怎么做。

    WITH '
    MATCH (a:authors{name:"Lui Lis"})-[:`WROTE`]->(b:papers)-[:`REFERS_TO`]->(c:fieldsofstudy)
    RETURN c.name AS field_of_study, count(b) AS number_of_papers
    ' AS query
    UNWIND RANGE(0, 4) AS i
    WITH i, query, datetime.realtime().epochMillis AS start
    CALL apoc.cypher.doIt(query, NULL) YIELD value
    WITH i, MAX(datetime.realtime().epochMillis-start) AS execTime
    WITH collect(execTime) AS per_query_time, AVG(execTime) AS avg_time
    UNWIND per_query_time AS x
    RETURN x, RANGE(0, 4) AS y, avg_time
    

    你能帮帮我吗

    1 回复  |  直到 2 年前
        1
  •  0
  •   cybersam    2 年前

    你所说的“序列号”是什么意思还不清楚。

    如果你愿意 y 与相同 i ,此查询应能工作:

    WITH '
      MATCH (a:authors{name:"Lui Lis"})-[:`WROTE`]->(b:papers)-[:`REFERS_TO`]->(c:fieldsofstudy)
      RETURN c.name AS field_of_study, count(b) AS number_of_papers
    ' AS query
    UNWIND RANGE(0, 4) AS i
    WITH i, query, datetime.realtime().epochMillis AS start
    CALL apoc.cypher.doIt(query, NULL) YIELD value
    WITH i, MAX(datetime.realtime().epochMillis-start) AS execTime
    WITH COLLECT({x: execTime, y: i}) AS per_query_times, AVG(execTime) AS avg_time
    UNWIND per_query_times AS z
    RETURN z.x AS x, z.y AS y, avg_time
    

    如果你愿意 y 作为每个查询时间的索引(跨所有 值),将上述查询的最后3行替换为:

    ...
    WITH COLLECT(execTime) AS per_query_times, AVG(execTime) AS avg_time
    UNWIND RANGE(0, SIZE(per_query_times)-1) AS y
    RETURN per_query_times[y] AS x, y, avg_time