function DB_get_unused_randomnumbers($userstr)
{
- $r = DB_query_array(" SELECT randomnumbers FROM Game".
- " WHERE randomnumbers NOT IN".
- " (SELECT randomnumbers FROM Game".
- " LEFT JOIN Hand ON Game.id=Hand.game_id".
- " WHERE user_id IN (". $userstr .")".
- " GROUP BY randomnumbers".
- " )");
+ /* optimized version of this query using temporary tables (perhaps we should use a procedure here?).
+ First we create a copy of the Game table using just the gameid and the cards.
+ Then in a second round we delete all the gameids of games where our players are in.
+ At the end we return only the first entry in the temporary table.
+ */
+ DB_query("DROP TEMPORARY TABLE IF EXISTS gametmp;");
+ DB_query("CREATE TEMPORARY TABLE gametmp SELECT id,randomnumbers FROM Game;");
+ DB_query("DELETE FROM gametmp WHERE id IN (SELECT game_id FROM Hand WHERE user_id IN (".$userstr."));");
+
+ $r = DB_query_array("SELECT randomnumbers FROM gametmp LIMIT 1;");
+ DB_query("DROP TEMPORARY TABLE IF EXISTS gametmp;");
+
if($r)
return $r[0];
else