Skip to content

Conversation

@fpringle
Copy link
Owner

@fpringle fpringle commented Aug 14, 2025

Thanks to our dynamic Opaleye effect, we can write an alternative interpreter which, as well as performing SQL operations as before, will also keep a tally of the number of SELECTs, 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 Opaleye operations 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 of SELECTs should not depend on the number of Users or their Transactionss. We would expect the number of SELECTs to remain basically constant (O(1)), while the execution time might grow linearly (O(u * t)). If we notice that the number of SELECTs 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.

@fpringle fpringle marked this pull request as ready for review August 15, 2025 07:26
@fpringle fpringle merged commit 4ae9104 into main Aug 15, 2025
24 checks passed
@fpringle fpringle deleted the fpringle/counting branch August 15, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant