Buy Percona ServicesBuy Now!

Per-query variable statement

Percona Server has implemented per-query variable statement support. This feature provides the ability to set variable values only for a certain query, after execution of which the previous values will be restored. Per-query variable values can be set up with the following command:

mysql> SET STATEMENT <variable=value> FOR <statement>;


If we want to increase the sort_buffer_size value just for one specific sort query we can do it like this:

mysql> SET STATEMENT sort_buffer_size=100000 FOR SELECT name FROM name ORDER BY name;

This feature can also be used with max_execution_time to limit the execution time for a specific query:

mysql> SET STATEMENT max_execution_time=1000 FOR SELECT name FROM name ORDER BY name;

We can provide more than one variable we want to set up:

mysql> SET STATEMENT sort_buffer_size=100000, max_statement_time=1000 FOR SELECT name FROM name ORDER BY name;

Version Specific Information

  • 5.7.10-1 Feature ported from Percona Server 5.6
Visit Percona Store

General Inquiries

For general inquiries about our open source software and database management tools, please send us your question and someone will contact you.