diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-01-15 19:13:32 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-01-15 19:13:32 +0100 |
commit | d3935adf7a4ea943583e9e51fe8fa8a2c14521dd (patch) | |
tree | 4125365a32fa25dde9e79ccfb4dcd10269071607 /sql/handler.cc | |
parent | 85ea99dcaf8fd91fa566a78062dbfa416c2309fe (diff) | |
parent | 14ba37f76f87cc48cae62eb6bdf3cda294dff78d (diff) | |
download | mariadb-git-d3935adf7a4ea943583e9e51fe8fa8a2c14521dd.tar.gz |
mysql-5.5.29 merge
Diffstat (limited to 'sql/handler.cc')
-rw-r--r-- | sql/handler.cc | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index 679ef346fbb..11265abb9d0 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2334,18 +2334,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)) { - if ((!(error= ha_rnd_init(1)))) + if (!(error= ha_rnd_init(1))) { - while ((error= ha_rnd_next(buf)) == HA_ERR_RECORD_DELETED) ; - (void) ha_rnd_end(); + while ((error= ha_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 */ - if (!(error = ha_index_init(primary_key, 0))) + if (!(error= ha_index_init(primary_key, 0))) + { error= ha_index_first(buf); - (void) ha_index_end(); + const int end_error= ha_index_end(); + if (!error) + error= end_error; + } } DBUG_RETURN(error); } @@ -2744,7 +2751,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(); - ha_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=ha_index_last(table->record[1]); @@ -2775,13 +2790,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); ha_index_end(); (void) extra(HA_EXTRA_NO_KEYREAD); *first_value= nr; + return; } |