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?
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