Skip to content

QueryExecutionCount statistic does not count all queries #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
deAtog opened this issue Mar 29, 2021 · 5 comments
Closed

QueryExecutionCount statistic does not count all queries #2714

deAtog opened this issue Mar 29, 2021 · 5 comments

Comments

@deAtog
Copy link
Contributor

deAtog commented Mar 29, 2021

When loading data from a session there are several cases where queries are executed without being counted in the QueryExecutionCount. E.g. The following code will cause the QueryExecutionCount to be incremented:

Entity e = session.QueryOver<Entity>()
    .Where(e => e.Id == id)
    .SingleOrDefault();

However, the following does NOT increment the QueryExecutionCount:

Entity e = session.Get<Entity>(id);

The implications of this issue is that tests which rely on this statistic are broken as the statistic does not accurately represent the number database queries executed.

@bahusoid
Copy link
Member

bahusoid commented Mar 29, 2021

the following does NOT increment the QueryExecutionCount:
session.Get(id)

It looks intentional to me. Query prefix here is not about any DB queries - but about loading via Query API. session.Get is counted separately in EntityLoadCount

@deAtog
Copy link
Contributor Author

deAtog commented Mar 29, 2021

@bahusoid The current usage hides unexpected behavior as tests cannot verify the total number of queries actually executed against the database. session.Get is merely one such example, there are many others. Just because something functions correctly does not mean it's implemented correctly. This issue is related to another issue that I have yet to post. Without a fix for this issue, tests cannot be written to correct the unexpected behavior as the EntityLoadCount is correct, but the queries executed and the query count is wrong.

@fredericDelaporte
Copy link
Member

fredericDelaporte commented Mar 29, 2021

Query Statistics are not about SQL queries as explained by bahusoid, but about NHibernate queries. A get or load is not a NHibernate query. Trying to use them for counting SQL queries cannot be reliable, they are just not meant for this. Changing them for counting SQL queries would corrupt its semantic, and would be a breaking change.

@deAtog
Copy link
Contributor Author

deAtog commented Mar 30, 2021

@fredericDelaporte Yes, I understand. Maybe another metric should be added to measure/count all database queries executed? For the time being, I'll see if the other metrics capture the inconsistent behavior I'm seeing as suggested by @bahusoid.

@fredericDelaporte
Copy link
Member

I would need to dig the code a bit to asses this, but maybe an interceptor or some events could allow you to get this kind of statistics. So no built-in way, but it may be an injection point allowing you to build the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants