Bug #24987 opt_sum_query does not handle -1 results from handler methods.
Submitted: 12 Dec 2006 0:51 Modified: 9 Feb 2007 20:26
Reporter: Sean Pringle Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:4.1, 5.0 OS:
Assigned to: Igor Babaev
Tags: bfsm_2006_12_21

[12 Dec 2006 0:51] Sean Pringle
Description:
When opt_sum_query returns -1 (impossible conditions), the caller assumes that the query simply cannot produce any rows (see JOIN::optimize). However opt_sum_query can also return -1 when table handler methods return -1. When that occurs, a table handler error could result in a query that produces no rows rather than having an error reported back to the client.

How to repeat:
If handler error is -1, then this will return -1.

if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE)
return -1; // No rows matching WHERE
/* HA_ERR_LOCK_DEADLOCK or some other error */
table->file->print_error(error, MYF(0));
return(error);
}

Suggested fix:
Apparently it is valid for handler methods to return -1 (is this documented either way?). If they return a recognized error (HA_*) then this problem cannot occur.
[12 Dec 2006 12:12] Miguel Solorzano
Thank you for the bug report.
[30 Jan 2007 21:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/19040

ChangeSet@1.2600, 2007-01-30 13:06:36-08:00, igor@olga.mysql.com +2 -0
  Fixed bug #24987.
  Made the function opt_sum_query to return HA_ERR_KEY_NOT_FOUND when
  no matches were found (instead of -1 it returned prior this patch).
  This changes allow us to avoid possible conflicts with return values
  from user-defined handler methods which also may return -1. 
  No particular test cases are provided with this fix.
[3 Feb 2007 6:10] Igor Babaev
The fix has been pushed into 5.0.36, 5.1.16-beta main trees.
 
Yet to be pushed into 4.1 main tree as well.
[9 Feb 2007 8:39] Sergey Glukhov
fixed in 4.1.23
[9 Feb 2007 20:26] Paul Dubois
Noted in 4.1.23, 5.0.36, 5.1.16 changelogs.

A return value of -1 from user-defined handlers was not handled well
and could result in conflicts with server code.