statistics.getQueries does not show all queries sent to DB

Im working an app using Postgres and spring-data-jpa. As part of the app Im trying to have it show both the statistics from Hibernate as well as the resulting queries. The point is to help educate devs about the impacts of various types of fetches, etc…

What I am noticing is that the number of distinct queries that show up in my logs if I use show_sql: true and the results that show up in statistics.getQueries don’t align. Specifically the show_sql output has all of the queries used to fetch the associated entities, where getQueries only has 2 (one for retrieval of the main entity and one for a count as part of using pagination),

Can someone explain to me why getQueries doesn’t show all of the unique queries that need to be issued, but show_sql does? Why wouldn’t those 2 entries match?

The query statistics are only for HQL queries. There are also statistics for entity loads and fetches, but not every SQL query contributes to these statistics.
Overall, statistics aren’t that well defined, so it’s not always clear what the expectations are. If you have certain requirements, I would suggest you start talking about them in our Zulip chat. Knowing the requirements better, we can guide you towards a potential solution or describe a feature/improvement for future development.