Keep a running tally of how many SQL operations have been performed #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks to our dynamic
Opaleyeeffect, we can write an alternative interpreter which, as well as performing SQL operations as before, will also keep a tally of the number ofSELECTs,INSERTs etc that have been performed. This is really useful for debugging.The intended use-case is a sort of bench mark that runs several
Opaleyeoperations for different "sizes", counts the SQL operations, and prints the tallies to the console. This lets us detect if some implementations are ineffecient. For example, for a typical simple read operation e.g.getUserTransactions :: [UserId] -> Eff es [[Transaction]], the number ofSELECTs should not depend on the number ofUsers or theirTransactionss. We would expect the number ofSELECTs to remain basically constant (O(1)), while the execution time might grow linearly (O(u * t)). If we notice that the number ofSELECTs is actually growing linearly, clearly there's an inefficiency in our query design.I've already used this in a real-world project, and it was remarkably useful to detect inefficient queries.