Reputation: 293
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?
Upvotes: 1
Views: 249
Reputation: 9
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;
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
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)
}
Upvotes: -1
Reputation: 151
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 < 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)
-> 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
From here, you can check the execution time.
Upvotes: 1
Reputation: 135
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.
Upvotes: 0
Reputation: 425
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)
Upvotes: 0
Reputation: 675
You can use EXPLAIN ANALYZE
inside the cypher function. For example:
SELECT * FROM cypher('test', $$
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.
Upvotes: 0