SQL_BIG_RESULT is an optional SELECT modifier available in MySQL and MariaDB. When placed immediately after SELECT, it tells the optimizer that the result set will be large. For GROUP BY or DISTINCT operations, the server prefers writing the intermediate results to a disk-based temporary table and performing sorting with the MyISAM storage engine. This can be faster than using in-memory temporary tables that later require on-the-fly merging, especially when the grouping columns are not indexed and the output is huge.Important behaviors:- Only meaningful with GROUP BY or DISTINCT. Otherwise it is ignored.- Can improve performance for multi-million-row outputs by reducing memory pressure and avoiding temporary table conversion during execution.- May slow down small or moderately sized queries because disk I/O is higher than memory access.- Mutually exclusive with SQL_SMALL_RESULT. If both are given, the last one wins.- It has no effect in other RDBMS like PostgreSQL or SQL Server; those parsers will raise a syntax error.
MySQL 3.23
Apply it to GROUP BY or DISTINCT queries that will return many rows so MySQL can write the intermediate results to disk early and avoid memory overuse.
No. It can improve very large aggregations but may hurt smaller ones because disk I/O is slower than memory. Test both approaches.
It is MySQL and MariaDB specific. Other databases will not recognize it and will throw a syntax error.
Both keywords can appear, but the last one in the modifier list overrides the other. Only one behavior is active.