Bug #12062 Query results split between two connections
Submitted: 20 Jul 2005 15:36 Modified: 26 Jul 2005 14:50
Reporter: Ronen Botzer Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:Ver 4.1.9-log (Source) OS:pc-linux-gnu on i686
Assigned to: CPU Architecture:Any

[20 Jul 2005 15:36] Ronen Botzer
Description:
I'm connecting to the same database server using the same php script on two different apache servers (www and www-test).  The two apache servers are on two separate boxes with different hardware, but both boxes have the exact same version of apache and the same version of debian.
I had turned query caching on the server, allocating 20MB for it.  Over a week the cache had utilized around 1MB.

The script execute three queries in a row:
  /**
  * @access public static
  * @param integer $subscribers - pass by reference
  * @param integer $shows - pass by reference
  * @param integer $channels - pass by reference
  */
  public static function getStats (&$subscriptions, &$shows, &$channels) {
    $dbLink = getDBLink();
    $query = "SELECT SUM(subscriptions) AS num FROM channels";
    $res = mysql_query ($query, $dbLink);
    if (is_resource ($res) && (mysql_num_rows($res) > 0)) {
      $row = mysql_fetch_assoc ($res);
      $subscriptions = $row['num'];
      mysql_free_result ($res);
    }

    $query = "SELECT COUNT(*) AS num FROM ".DBNAME.".shows s JOIN ".XBT_DBNAME.".xbt_files x ON s.xbtFilesFid=x.fid  WHERE x.flags=0 AND s.showID IN (SELECT showID from showsToChannels WHERE channelID IN (SELECT channelID FROM channels))";
    $res = mysql_query ($query, $dbLink);
    if (is_resource ($res) && (mysql_num_rows($res) > 0) ) {
      $row = mysql_fetch_assoc ($res);
      $shows = $row['num'];
    }

    $query = "SELECT COUNT(channelID) AS num FROM channels";
    $res = mysql_query ($query, $dbLink);
    if (is_resource ($res) && (mysql_num_rows($res) > 0)) {
      $row = mysql_fetch_assoc ($res);
      $channels = $row['num'];
      mysql_free_result ($res);
    }
  }

As you can see I'm expecting three results stored back in the three variables I passed by reference.

Rarely (about twice a day for about 5 minutes at a time) I get a very odd behavior - the query will return on www:
null, 200, null
and on the other server
50, null, 2000 (example values).

In both cases the actual result should be
50, 200, 2000

While this is happening running the same queries from the command line mysql client returns the desired 50,200,2000

As I've said - this is rare, but consistent.  I've turned off the query cache for now to see if this behavior happens without caching queries.

How to repeat:
The error can't be forced to reproduce, but it happens consistently a few times a day.
[26 Jul 2005 14:50] Aleksey Kishkin
Hi! 
tested against mysql 4.1.13 and linux slackware (test worked about 2 days).  Was not able to reproduce this behaviour. For now I set the status as "can't repeat". If you have any ideas how to reproduce it, please don't hesitate to reopen this bug report.