SQL_SMALL_RESULT

SQL_SMALL_RESULT is a MySQL-specific command modifier. When incorporated in a SELECT statement, it instructs the server to store the result set in memory, if it's small enough, instead of writing it to a temporary disk table. This may improve the performance of some queries. It's typically used when an ORDER BY clause is going to sort a few rows only. The decision to use memory or not belongs to the optimizer, based on the query and server configuration.

Example

SELECT SQL_SMALL_RESULT product_name, product_price
FROM products
ORDER BY product_price;

Output

+------------------+---------------+
| product_name | product_price |
+------------------+---------------+
| LED TV | 350.99 |
| Refrigerator | 700.50 |
| Washing Machine | 500.75 |
| Air Conditioner | 850.00 |
+------------------+---------------+

Explanation

The SQL_SMALL_RESULT modifier is used in the SQL query. It informs MySQL to store the result of the query in a temporary table, which then sorts the table. This is useful when expecting a small result set from a large database.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.