Stopping expensive queries before they start
adpgtech.blogspot.com
adpgtech.blogspot.com
For example, imagine a system where items are soft-deleted immediately upon user action, but not actually deleted for a few days to facilitate restoration (recycle bin).
There is going to be some nightly/hourly/scheduled job that actually really deletes these records. Initially it will have little work to do, but over time as the system grows it may become slow. Typically this would be hard to separate from other slow queries, you would have to catch it running while causing other queries to pile up. Query time isn't necessarily useful here as you may have enough I/O to cover the slow query replacing pages in the cache, but that I/O would be better serving user facing requests instead of this cleanup job.
This feature allows for the "work" it really takes to serve the query to cause it to error, instead of time which may grind down for other reasons. At this point you know its time to re-think the soft-deletion strategy, you disable the job. Maybe you sweep more frequently? Maybe you keep a look-aside of things to sweep to avoid scans? Maybe you sweep during a low-traffic time? Whatever. It buys you time to think.
I wish there were something comparable for MySQL.
Would expect these decisions to be made at design time, or perhaps that alerts are sent to ops when these situations occur.
On the flip side, we have had issues in production that really slowed down our service or even took it down. In those situations it is much more preferable to stop those specific queries than to have the entire service unresponsive.
We do try to keep the reporting limited to what can be done efficiently, but I don't know if it's really viable to avoid everything ahead of time.
Except for the simplest cases, the application has no clue which queries will be problematic. Who knows that information? Only the database.
However if you have users building up dynamic queries, etc it might be really nice to fail gracefully if they go overboard, or if there is some temporary condition that is preventing an optimal execution plan. Better than chewing up all of your resources in any case.
I think this could be really helpful in test environments as well.