Bug #72540 MAX_STATEMENT_TIME uses confusing syntax
Submitted: 5 May 2014 18:46 Modified: 27 Aug 2015 4:15
Reporter: Morgan Tocker Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S3 (Non-critical)
Version:5.7 DMR4 OS:Any
Assigned to: CPU Architecture:Any

[5 May 2014 18:46] Morgan Tocker
Description:
Via Chip Turner / WebscaleSQL mailing list at https://groups.google.com/forum/#!topic/webscalesql/r1Zwnhvi72I 
-----

It seems Oracle is taking the MAX_STATEMENT_TIME patch for 5.7, which is awesome, but I have a proposal for changing the syntax before it becomes baked into the upstream version.  For context, currently you can't set a time limit on the time the server will spend executing a query.  This patch allows it, via either a session variable (MAX_STATEMENT_TIME) or as part of a query.  Specifically, you can do:

SELECT MAX_STATEMENT_TIME = 90 * FROM foo;

and it sets MAX_STATEMENT_TIME to 90, just for that query.

When I first saw the syntax, I was confused by the '90 * FROM' -- it didn't feel right.  The rest of the syntax just didn't feel natural to me overall, so after thinking more about it, and discussing with other mysql people here, a consensus emerged that we might want to change it before it's baked into upstream.  I can see why it isn't a hint (it's reasonable to want a hard failure if a timeout can't be enforced, say, because the server isn't configured)

These discussions brought two ideas:

Add a RESOURCE LIMIT clause to SELECT, allowing something like:

SELECT * FROM Foo WITH RESOURCE LIMIT MAX_STATEMENT_TIME = 90;

or, more general, add "for this statement only" a session variable:

SELECT * FROM Foo WITH SESSION MAX_STATEMENT_TIME =90;

Currently, I believe "WITH" only is used for "WITH ROLLUP" and shouldn't cause any grammar problems.  This gives us a more extensible syntax for future uses while being easier to understand when reading a query.

I also think the name would be clearer as "MAX_STATEMENT_MILLISECONDS" -- we've found, very often, it's much simpler when configuration options (names in config files, command line parameters, etc) have the unit they expect as part of the name.  It eliminates all ambiguity, especially since MySQL itself tends to prefer seconds for most units.

Thoughts?

-----

How to repeat:
N/A

Suggested fix:
Thread provides a couple of suggestions for alternative syntax:

* SELECT * FROM Foo WITH RESOURCE LIMIT MAX_STATEMENT_TIME = 90;
* SELECT * FROM Foo WITH SESSION MAX_STATEMENT_TIME =90;
* Changing from seconds to milliseconds for unit + renaming to MAX_STATEMENT_MILLISECONDS
[6 May 2014 3:53] Laurynas Biveinis
Related: http://dev.mysql.com/worklog/task/?id=681
[6 May 2014 4:36] Erlend Dahl
Thank you for the feature request.
[27 Aug 2015 4:15] Erlend Dahl
Duplicate of 

Bug#77460 Remove old-style MAX_STATEMENT_TIME hint (replace with MAX_EXECUTION_TIME)