summaryrefslogtreecommitdiff
path: root/sql/handler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/handler.cc')
-rw-r--r--sql/handler.cc47
1 files changed, 38 insertions, 9 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 27309a4b1d7..f4eb89912e9 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2291,16 +2291,25 @@ int handler::read_first_row(uchar * buf, uint primary_key)
if (stats.deleted < 10 || primary_key >= MAX_KEY ||
!(index_flags(primary_key, 0, 0) & HA_READ_ORDER))
{
- (void) ha_rnd_init(1);
- while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
- (void) ha_rnd_end();
+ if (!(error= ha_rnd_init(1)))
+ {
+ while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED)
+ /* skip deleted row */;
+ const int end_error= ha_rnd_end();
+ if (!error)
+ error= end_error;
+ }
}
else
{
/* Find the first row through the primary key */
- (void) ha_index_init(primary_key, 0);
- error=index_first(buf);
- (void) ha_index_end();
+ if (!(error= ha_index_init(primary_key, 0)))
+ {
+ error= index_first(buf);
+ const int end_error= ha_index_end();
+ if (!error)
+ error= end_error;
+ }
}
DBUG_RETURN(error);
}
@@ -2695,7 +2704,15 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
table->mark_columns_used_by_index_no_reset(table->s->next_number_index,
table->read_set);
column_bitmaps_signal();
- index_init(table->s->next_number_index, 1);
+
+ if (ha_index_init(table->s->next_number_index, 1))
+ {
+ /* This should never happen, assert in debug, and fail in release build */
+ DBUG_ASSERT(0);
+ *first_value= ULONGLONG_MAX;
+ return;
+ }
+
if (table->s->next_number_keypart == 0)
{ // Autoincrement at key-start
error=index_last(table->record[1]);
@@ -2725,13 +2742,25 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
}
if (error)
- nr=1;
+ {
+ if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND)
+ {
+ /* No entry found, start with 1. */
+ nr= 1;
+ }
+ else
+ {
+ DBUG_ASSERT(0);
+ nr= ULONGLONG_MAX;
+ }
+ }
else
nr= ((ulonglong) table->next_number_field->
val_int_offset(table->s->rec_buff_length)+1);
- index_end();
+ ha_index_end();
(void) extra(HA_EXTRA_NO_KEYREAD);
*first_value= nr;
+ return;
}