EnableBigSqlSelects.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Give\Framework\Database\Actions; |
| 6 | |
| 7 | class EnableBigSqlSelects |
| 8 | { |
| 9 | /** |
| 10 | * @since 2.22.0 |
| 11 | * |
| 12 | * Enables mysql big selects for the session using a session system variable. |
| 13 | * |
| 14 | * This is necessary for hosts that have an arbitrary MAX_JOIN_SIZE limit, which prevents more complex queries from |
| 15 | * running properly. Setting SQL_BIG_SELECTS ignores this limit. This is also done by WooCommerce, supporting the |
| 16 | * idea that this is a viable option. There also doesn't seem to be a way for hosts to prevent this. |
| 17 | * |
| 18 | * @see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_big_selects |
| 19 | * @see https://dev.mysql.com/doc/refman/5.7/en/system-variable-privileges.html |
| 20 | * |
| 21 | */ |
| 22 | public function __invoke() |
| 23 | { |
| 24 | static $bigSelects = false; |
| 25 | |
| 26 | if (!$bigSelects) { |
| 27 | global $wpdb; |
| 28 | |
| 29 | $wpdb->query('SET SESSION SQL_BIG_SELECTS=1;'); |
| 30 | |
| 31 | $bigSelects = true; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 |