在Apache AGE中使用AGE-Viewer-GO测量查询执行时间

huangapple go评论52阅读模式
英文:

Measuring Query Execution Time in Apache AGE Using AGE-Viewer-GO

问题

我目前正在使用Apache AGE进行图数据管理,并使用AGE-Viewer-GO执行一组查询。

我现在想要做的是测量这个(和其他)查询的执行时间。AGE-Viewer-GO中是否有内置函数或功能允许我测量查询执行所需的时间?
如果没有,是否有推荐的方法来实现这一目标?

英文:

I am currently working with Apache AGE for graph data management and I'm executing a set of queries using AGE-Viewer-GO.

What I want to do now is measure the execution time of this (and other) queries. Is there a built-in function or feature in AGE-Viewer-GO that allows me to measure how long a query takes to execute?
If not is there a recommended way to achieve this?

答案1

得分: 3

以下是翻译好的内容:

使用以下GO模板来测量查询执行时间的最佳方法:

start := time.Now()
// 这里是您的查询执行
elapsed := time.Since(start)

fmt.Println("查询耗时 %s", elapsed)
英文:

The optimal way to measure the query execution time is by using the following template written in GO:

start := time.Now()
// Here goes your query execution
elapsed := time.Since(start)

fmt.Println("Query took %s", elapsed)

答案2

得分: 1

解释分析(Explain Analyze)是获取查询执行时间的最佳方法。它的格式非常简单和易懂。您只需在查询之前写上"Explain Analyze"。

在这里,"query" 意味着整个查询,下面是另一个示例:

EXPLAIN ANALYZE SELECT *
FROM tenk1 t1, tenk2 t2
WHERE t1.unique1 < 10 AND t1.unique2 = t2.unique2;

Explain Analyze 的输出如下:

QUERY PLAN
-------------------------------------------------------------
Nested Loop  (cost=4.65..118.62 rows=10 width=488) (actual time=0.128..0.377 rows=10 loops=1)
->  Bitmap Heap Scan on tenk1 t1  (cost=4.36..39.47 rows=10 width=244) (actual time=0.057..0.121 rows=10 loops=1)
    Recheck Cond: (unique1 < 10)
    ->  Bitmap Index Scan on tenk1_unique1  (cost=0.00..4.36 rows=10 width=0) (actual time=0.024..0.024 rows=10 loops=1)
          Index Cond: (unique1 < 10)
->  Index Scan using tenk2_unique2 on tenk2 t2  (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10)
    Index Cond: (unique2 = t1.unique2)
Planning time: 0.181 ms
Execution time: 0.501 ms

从这里,您可以查看执行时间。

英文:

Explain Analyze is the best way to get the query execution time. It's format is pretty simple and easy. You just have to write Explain Analyze before your query.

Explain Analyze Query

Here query means the whole query, another example of that is mentioned below:

EXPLAIN ANALYZE SELECT *
FROM tenk1 t1, tenk2 t2
WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2;

The output shown by the Explain Analyze is as follows:

 QUERY PLAN
 -------------------------------------------------------------
 Nested Loop  (cost=4.65..118.62 rows=10 width=488) (actual time=0.128..0.377 rows=10 loops=1)
 -&gt;  Bitmap Heap Scan on tenk1 t1  (cost=4.36..39.47 rows=10 width=244) (actual time=0.057..0.121 rows=10 loops=1)
     Recheck Cond: (unique1 &lt; 10)
     -&gt;  Bitmap Index Scan on tenk1_unique1  (cost=0.00..4.36 rows=10 width=0) (actual time=0.024..0.024 rows=10 loops=1)
           Index Cond: (unique1 &lt; 10)
 -&gt;  Index Scan using tenk2_unique2 on tenk2 t2  (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10)
     Index Cond: (unique2 = t1.unique2)
 Planning time: 0.181 ms
 Execution time: 0.501 ms

From here, you can check the execution time.

答案3

得分: 0

你可以在cypher函数内部使用EXPLAIN ANALYZE。例如:

SELECT * FROM cypher('test', $$
EXPLAIN ANALYZE MATCH (u)
RETURN u
$$) AS (result agtype);

这将返回所述查询的查询计划、规划时间和执行时间。

英文:

You can use EXPLAIN ANALYZE inside the cypher function. For example:

SELECT * FROM cypher(&#39;test&#39;, $$                                                                    
EXPLAIN ANALYZE MATCH (u)
RETURN u
$$) AS (result agtype);

This will return the query plan, the planning time and the execution time for the stated query.

答案4

得分: 0

这是翻译好的部分:

"我不认为有内置方法来实现这一点。要实现这一点,您可以在查询执行之前和之后记录时间,然后进行相减。

以下是您可以执行的步骤:

start := time.Now()
//在这里执行您的所有查询
end := time.Now()

duration := end.Sub(start)"
英文:

I don't think that there is a inbuilt method for this. What you can do to achieve this is recording time before & after query execution & then subtracting it.

Here is how you can do:

start := time.Now()
//ALL YOUR QUERY EXECUTION GOES HERE
end := time.Now()

duration := end.Sub(start)

答案5

得分: 0

你可以使用 EXPLAIN ANALYZE PostgreSQL,不仅会显示常规EXPLAIN命令的执行计划,还会运行查询并收集实际的运行时统计信息。这些统计信息包括实际处理的行数以及执行计划中每个步骤所花费的时间。

EXPLAIN ANALYZE文档

英文:

you can use EXPLAIN ANALYZE PostgreSQL not only displays the execution plan as with a regular EXPLAIN command but also runs the query and collects actual runtime statistics. These statistics include the actual number of rows processed and the time taken by each step in the execution plan.

EXPLAIN ANALYZE documentation

答案6

得分: -1

You can easily check your execution time of query by using EXPLAIN ANALYZE of PostgreSQL. This will also explain the execution plan.
This is an example from the documentation on how it works

EXPLAIN ANALYZE SELECT *
FROM tenk1 t1, tenk2 t2
WHERE t1.unique1 < 10 AND t1.unique2 = t2.unique2;

If you want to check execution time using GO you can use the time package that provides a timer. For example

package main

import (
    "fmt"
    "time"
)

func main() {
    query_start := time.Now() // gets the current time

    // Put your code here
    // ...

    time_from_query := time.Since(query_start) // Calculate the elapsed time

    fmt.Printf("Execution time: %s\n", time_from_query)
}
英文:

You can easily check your execution time of query by using EXPLAIN ANALYZE of PostgreSQL. This will also explain the execution plan.
This is an example from the documentation on how it works

EXPLAIN ANALYZE SELECT *
FROM tenk1 t1, tenk2 t2
WHERE t1.unique1 &lt; 10 AND t1.unique2 = t2.unique2;

                                                           QUERY PLAN
-------------------------------------------------------------------​--------------------------------------------------------------
 Nested Loop  (cost=4.65..118.62 rows=10 width=488) (actual time=0.128..0.377 rows=10 loops=1)
   -&gt;  Bitmap Heap Scan on tenk1 t1  (cost=4.36..39.47 rows=10 width=244) (actual time=0.057..0.121 rows=10 loops=1)
         Recheck Cond: (unique1 &lt; 10)
         -&gt;  Bitmap Index Scan on tenk1_unique1  (cost=0.00..4.36 rows=10 width=0) (actual time=0.024..0.024 rows=10 loops=1)
               Index Cond: (unique1 &lt; 10)
   -&gt;  Index Scan using tenk2_unique2 on tenk2 t2  (cost=0.29..7.91 rows=1 width=244) (actual time=0.021..0.022 rows=1 loops=10)
         Index Cond: (unique2 = t1.unique2)
 Planning time: 0.181 ms
 Execution time: 0.501 ms

If you want to check execution time using GO you can use the time package that provides a timer. For example

package main

import (
	&quot;fmt&quot;
	&quot;time&quot;
)

func main() {
	query_start := time.Now() // gets the current time

	// Put your code here
	// ...

	time_from_query := time.Since(query_start) // Calculate the elapsed time

	fmt.Printf(&quot;Execution time: %s\n&quot;, time_from_query)
}

答案7

得分: -1

AGE-Viewer-GO 中没有专门用于测量 Apache AGE 查询执行时间的内置功能或特性。然而,您可以通过利用我所知道的 PostgreSQL 功能来实现这一目标。

PostgreSQL 的 pg_stat_statements 扩展会跟踪所有执行的 SQL 语句及其执行时间。为了了解查询性能,您可以启用这个扩展并查询 pg_stat_statements 视图。

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT pg_stat_statements_reset();
SQL_QUERY;
SELECT query, total_time, calls FROM pg_stat_statements;

希望对您有所帮助。

英文:

There isn't a single built-in function or feature in AGE-Viewer-GO that specifically measures the query execution time in Apache AGE. However, you can accomplish this by making use of a postgresql feature which I am aware of.

The pg_stat_statements extension for PostgreSQL keeps track of all performed SQL statements and their execution timings. To gain knowledge about query performance, you can enable this extension and query the pg_stat_statements view.

    CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
    SELECT pg_stat_statements_reset();
    SQL_QUERY;
    SELECT query, total_time, calls FROM pg_stat_statements;

Hope this helps.

huangapple
  • 本文由 发表于 2023年5月22日 02:00:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定