2

I have some tests on GitHub which record how much time it takes to execute a query and fetch all results.

If I check the execution plan, I get:

Index Scan using post_comment_pkey on post_comment postcommen0_  (cost=0.29..2716.48 rows=34752 width=43) (actual time=6.767..14.352 rows=34880 loops=1)
  Filter: (post_id = 1)
  Rows Removed by Filter: 34880
Planning time: 0.659 ms
Execution time: 14.840 ms

So, the query is using an index and executing in 15 ms.

However, on the Java side, after the ResultSet is fetched and processed, the time measurement indicates that it took 90 ms.

The only explanation would be that the Explain Analyze doe snot consider the fetch time and fetching 34880 records takes 50-60 ms.

Is this correct?

1
  • 4
    explain (analyze) does not send the data to the client. The 15ms is the raw time it takes the server to run the statement and read all the data from disk. 60ms for transmitting the data and processing 35k rows through JDBC doesn't sound wrong
    – user1822
    Commented Sep 2, 2016 at 15:31

2 Answers 2

2

Fetching performance is dependant of the client performance, available memory, cpu usage, network performance... I don't see how EXPLAIN ANALYZE could take this into account. So I would say your correct.

-1

Let's first understand what is Planning and Execution time:

  • Planning time When you run a query there is a lot of ways server can run this query. Query planner think and decide based on statistic of page. So Planning query is a time that query planner spend.
  • Execution time is actual time server spend for execution this query.

But time on java side you measured always will be greater than Execution time , because there is additional fetch time, which is also depends on client and infra.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.