From d4e4f2a58ce2e44e17e010b0c8a975c0701f660e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 13 Mar 2003 23:09:25 +0200 Subject: [PATCH] ha_innodb.cc: Fix bug: MySQL could erroneously return Empty set if InnoDB estimated index range size to 0 records though the range was not empty; MySQL also failed to do the next-key locking in the case of an empty index range sql/ha_innodb.cc: Fix bug: MySQL could erroneously return Empty set if InnoDB estimated index range size to 0 records though the range was not empty; MySQL also failed to do the next-key locking in the case of an empty index range --- sql/ha_innodb.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 0af1fb7b50a..ea8eaf6653e 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -3486,6 +3486,16 @@ ha_innobase::records_in_range( prebuilt->trx->op_info = (char*)""; + /* The MySQL optimizer seems to believe an estimate of 0 rows is + always accurate and may return the result 'Empty set' based on that. + The accuracy is not guaranteed, and even if it were, for a locking + read we should anyway perform the search to set the next-key lock. + Add 1 to the value to make sure MySQL does not make the assumption! */ + + if (n_rows == 0) { + n_rows = 1; + } + DBUG_RETURN((ha_rows) n_rows); }