I have created a report that pulls from a few different Postgres tables to show various traffic information. It shows information within a previous four-hour and next-four hour window from the current time. There are 10 queries that are executed on six tables. There are no aggregations or calculations for these queries, but this data is updated every couple of minutes (as the time changes).
If I have not opened this report for several hours, it takes about 15 seconds to query all of the data, but every data refresh after that only takes about two seconds if the report is left open.
My question is what is the difference between those two queries? Running the queries on my local SQL client takes about four seconds, so I'm trying to understand what contributes to the longer execute time on that initial query vs. the subsequent queries.