1

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?

Kamlesh Kumar
  • 351
  • 1
  • 7

13 Answers13

3

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)
Humza Tareen
  • 146
  • 6
1

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.

0

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.

Zainab Saad
  • 728
  • 1
  • 2
  • 8
0

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)
Huzaifa
  • 484
  • 4
  • 8
0

There is no built-in function or feature for that. However, using PostgreSQL's EXPLAIN ANALYZE in the cypher query statement gets this done.

EXPLAIN shows estimates while ANALYZE runs the query and returns the time to create the query plan, plus the time taken to execute the query according to that plan.

Therefore a sample query to check the runtime to return all nodes in graph will be:

SELECT * FROM cypher('graph_name', $$                                                                    
EXPLAIN ANALYZE MATCH (n)
RETURN n
$$) AS (output agtype);
Tito
  • 289
  • 8
0

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

Marcos Silva
  • 115
  • 5
0

There is no built in method to find and check the executed time of a query .To measure the execution time what you can do is use time or fmt methods available in GO.

start the timer before the query execution and stop it after query is being processed. subtract the start time from the end timer. In this way you can check the time taken by the query.

func main(){
// All your previous code 

t_start:=time.Now()
// Query, whose execution time you want to find.
t_end:=time.Now()

duration:=end.Sub(start)
fmt.Printf("Execution time: %s\n", duration)
}

don't forget to import the necessery libraries. "fmt", "time".

0

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)
}
0

Unfortunately, there is no built-in function for the measurement of execution time of the queries. But there is a way to do it.

You can use the time functionality package from GO. You can check the difference between the starting and completing time of query to measure the time taken by query for execution.

adil shahid
  • 125
  • 4
0

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.

Raja Rakshak
  • 168
  • 2
0

There is no built-in feature for measuring query execution time in AGE Viewer GO. However you can manually measure it using Go's time package. Record the start time before query execution and then calculate the elapsed time after the query has been executed.
Alternatively, you can use EXPLAIN ANALYZE before your query to get more detailed information about query execution which also includes time.

0

There is not any builtin function in AGE-Viewer-GO that allows you to measure how long the query takes to executes but there is a way to use the PostgreSQL Explain Analyze command in cypher quesry statement.

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

This will return planning time and execution time for the started query.

0

There is no built in function for measuring the length of execution of any query, but it can be achieved through using Explain Analyze command in cypher query.

Aadil Bashir
  • 111
  • 5