MySQL: "SELECT will check for more than MAX_JOIN_SIZE rows"
I am using PHP and MySQL. My program has a select query that includes joins. When I run it on localhost it works fine, but when I upload it to my server and try to execute it, it generates the following error:
The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
How can I fix this?
When using PHP, SQL_BIG_SELECTS = 1 must be set in a separate query before your main query. For example:
$mysqli = new mysqli("localhost", "root", "password", "db");
$mysqli->query("SET SQL_BIG_SELECTS=1"); //Set it before your main query
$results = $mysqli->query("SELECT a, b, c FROM test");
while($row = $results->fetch_assoc()){
echo '<pre>';
print_r ($row);
echo '</pre>';
}
source to share
The effect of the parameter is documented at http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_join_size .
You must filter the related records more strictly (so there are fewer records in each part of the query). If possible, start with a table where you can filter out most of the records with a simple WHERE clause.
source to share
I faced the same problem. His drupal site is not so surprised he crashed.
This was an old style request i.e. Select blah From table1, table2, table3 Where table1.id=table2.id And table2.some = 'thing'
Like @VolkerK, the solution was to move the where clauses filtered by the results of table2 to what is matched against table1 in table2 (in fact, join clauses), thus reducing the number of records that must match in table2 with table1 ...
source to share