diff options
author | unknown <monty@donna.mysql.com> | 2000-12-10 21:10:03 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2000-12-10 21:10:03 +0200 |
commit | 3b7b122832b1a60094dcce9eb57d125138b50d66 (patch) | |
tree | ce9dbc6a3d178089b8bffe3cc9cde360253a4f27 /sql/ha_berkeley.cc | |
parent | 1ab8254000703033713930a9bec93a1108bc298a (diff) | |
download | mariadb-git-3b7b122832b1a60094dcce9eb57d125138b50d66.tar.gz |
Bugfix when using a multi-part unique key in the SET and WHERE part
Put PRIMARY KEY and UNIQUE keys before other keys
Fixes for auto_increment keys for BDB tables
Docs/manual.texi:
Changelog
sql/ha_berkeley.cc:
Fixes for auto_increment keys
sql/sql_table.cc:
Put PRIMARY KEY and UNIQUE keys before other keys
sql/sql_update.cc:
Bugfix when using a multi-part unique key in the SET and WHERE part
Diffstat (limited to 'sql/ha_berkeley.cc')
-rw-r--r-- | sql/ha_berkeley.cc | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index fc293c1e8af..45a638c8424 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -1660,7 +1660,8 @@ longlong ha_berkeley::get_auto_increment() } else { - DBT row; + DBT row,old_key; + DBC *auto_cursor; bzero((char*) &row,sizeof(row)); uint key_len; KEY *key_info= &table->key_info[active_index]; @@ -1670,27 +1671,37 @@ longlong ha_berkeley::get_auto_increment() key_buff, table->record[0], table->next_number_key_offset); /* Store for compare */ - memcpy(key_buff2, key_buff, (key_len=last_key.size)); - /* Modify the compare so that we will find the next key */ - key_info->handler.bdb_return_if_eq= 1; - /* We lock the next key as the new key will probl. be on the same page */ - error=cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE | DB_RMW), - key_info->handler.bdb_return_if_eq= 0; - - if (!error || error == DB_NOTFOUND) + memcpy(old_key.data=key_buff2, key_buff, (old_key.size=last_key.size)); + error=1; + if (!(file->cursor(key_file[active_index], transaction, &auto_cursor, 0))) { - /* - Now search go one step back and then we should have found the - biggest key with the given prefix - */ - if (read_row(cursor->c_get(cursor, &last_key, &row, DB_PREV | DB_RMW), - table->record[1], active_index, &row, (DBT*) 0, 0) || - berkeley_key_cmp(table, key_info, key_buff2, key_len)) - error=1; // Something went wrong or no such key + /* Modify the compare so that we will find the next key */ + key_info->handler.bdb_return_if_eq= 1; + /* We lock the next key as the new key will probl. be on the same page */ + error=auto_cursor->c_get(auto_cursor, &last_key, &row, + DB_SET_RANGE | DB_RMW); + key_info->handler.bdb_return_if_eq= 0; + if (!error || error == DB_NOTFOUND) + { + /* + Now search go one step back and then we should have found the + biggest key with the given prefix + */ + error=1; + if (!auto_cursor->c_get(auto_cursor, &last_key, &row, DB_PREV | DB_RMW) + && !berkeley_cmp_packed_key(key_file[active_index], &old_key, + &last_key)) + { + error=0; // Found value + unpack_key(table->record[1], &last_key, active_index); + } + } + auto_cursor->c_close(auto_cursor); } } - nr=(longlong) - table->next_number_field->val_int_offset(table->rec_buff_length)+1; + if (!error) + nr=(longlong) + table->next_number_field->val_int_offset(table->rec_buff_length)+1; ha_berkeley::index_end(); (void) ha_berkeley::extra(HA_EXTRA_NO_KEYREAD); return nr; |