Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does loop in explain analyze statement mean?

I am profiling my query.

postgres=# explain analyze select * from student;
                                              QUERY PLAN
------------------------------------------------------------------------------------------------------
 Seq Scan on student  (cost=0.00..22.00 rows=1200 width=40) (actual time=0.005..0.005 rows=7 loops=1)
 Planning time: 0.035 ms
 Execution time: 0.019 ms
(3 rows)

I am not aware about what loop=1 mean in Seq Scan on student (cost=0.00..22.00 rows=1200 width=40) (actual time=0.005..0.005 rows=7 loops=1).

I have searched postgres documentation, but didn't find any good reference about loop parameter.

Thanks in advance.

like image 785
Mangu Singh Rajpurohit Avatar asked Apr 09 '18 13:04

Mangu Singh Rajpurohit


People also ask

How do you explain analyze?

EXPLAIN ANALYZE is a profiling tool for your queries that will show you where MySQL spends time on your query and why. It will plan the query, instrument it and execute it while counting rows and measuring time spent at various points in the execution plan.

Does analyze run the query?

In PostgreSQL, the EXPLAIN ANALYZE query allows obtaining actual run-time statistics on the required statement. Note that, unlike EXPLAIN, EXPLAIN ANALYZE actually runs the query, which means that you need to be careful with the DROP and UPDATE statements.

What is explain analyze in Postgres?

The ANALYZE option causes the statement to be actually executed, not only planned. Then actual run time statistics are added to the display, including the total elapsed time expended within each plan node (in milliseconds) and the total number of rows it actually returned.


1 Answers

PostgreSQL documentation does talk about this:

In some query plans, it is possible for a subplan node to be executed more than once. For example, the inner index scan will be executed once per outer row in the above nested-loop plan. In such cases, the loops value reports the total number of executions of the node, and the actual time and rows values shown are averages per-execution. This is done to make the numbers comparable with the way that the cost estimates are shown. Multiply by the loops value to get the total time actually spent in the node.

like image 125
Sami Kuhmonen Avatar answered Sep 21 '22 15:09

Sami Kuhmonen