Commit 73d7c19e authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #808

reduce complexity of pack_row and make it independent of whether
we have a hidden primary key

git-svn-id: file:///svn/mysql/tokudb-engine/src@3920 c7de825b-a66e-492c-adef-691d508d4ae1
parent 36967090
...@@ -1187,17 +1187,12 @@ ulong ha_tokudb::max_row_length(const uchar * buf) { ...@@ -1187,17 +1187,12 @@ ulong ha_tokudb::max_row_length(const uchar * buf) {
// [in] record - row in MySQL format // [in] record - row in MySQL format
// //
int ha_tokudb::pack_row(DBT * row, const uchar * record, bool new_row) { int ha_tokudb::pack_row(DBT * row, const uchar * record) {
uchar *ptr; uchar *ptr;
bzero((void *) row, sizeof(*row)); bzero((void *) row, sizeof(*row));
if (share->fixed_length_row) { if (share->fixed_length_row) {
row->data = (void *) record; row->data = (void *) record;
row->size = table_share->reclength; row->size = table_share->reclength;
if (hidden_primary_key) {
if (new_row) {
get_auto_primary_key(current_ident);
}
}
return 0; return 0;
} }
if (table_share->blob_fields) { if (table_share->blob_fields) {
...@@ -1209,15 +1204,11 @@ int ha_tokudb::pack_row(DBT * row, const uchar * record, bool new_row) { ...@@ -1209,15 +1204,11 @@ int ha_tokudb::pack_row(DBT * row, const uchar * record, bool new_row) {
memcpy(rec_buff, record, table_share->null_bytes); memcpy(rec_buff, record, table_share->null_bytes);
ptr = rec_buff + table_share->null_bytes; ptr = rec_buff + table_share->null_bytes;
for (Field ** field = table->field; *field; field++) for (Field ** field = table->field; *field; field++) {
ptr = (*field)->pack(ptr, (const uchar *) ptr = (*field)->pack(ptr, (const uchar *)
(record + field_offset(*field))); (record + field_offset(*field)));
if (hidden_primary_key) {
if (new_row) {
get_auto_primary_key(current_ident);
}
} }
row->data = rec_buff; row->data = rec_buff;
row->size = (size_t) (ptr - rec_buff); row->size = (size_t) (ptr - rec_buff);
return 0; return 0;
...@@ -1601,12 +1592,19 @@ int ha_tokudb::write_row(uchar * record) { ...@@ -1601,12 +1592,19 @@ int ha_tokudb::write_row(uchar * record) {
int error; int error;
statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status); statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) {
table->timestamp_field->set_time(); table->timestamp_field->set_time();
if (table->next_number_field && record == table->record[0]) }
if (table->next_number_field && record == table->record[0]) {
update_auto_increment(); update_auto_increment();
if ((error = pack_row(&row, (const uchar *) record, 1))) }
if ((error = pack_row(&row, (const uchar *) record))){
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
}
if (hidden_primary_key) {
get_auto_primary_key(current_ident);
}
u_int32_t put_flags = key_type[primary_key]; u_int32_t put_flags = key_type[primary_key];
THD *thd = ha_thd(); THD *thd = ha_thd();
...@@ -1705,13 +1703,13 @@ int ha_tokudb::update_primary_key(DB_TXN * trans, bool primary_key_changed, cons ...@@ -1705,13 +1703,13 @@ int ha_tokudb::update_primary_key(DB_TXN * trans, bool primary_key_changed, cons
// Primary key changed or we are updating a key that can have duplicates. // Primary key changed or we are updating a key that can have duplicates.
// Delete the old row and add a new one // Delete the old row and add a new one
if (!(error = remove_key(trans, primary_key, old_row, old_key))) { if (!(error = remove_key(trans, primary_key, old_row, old_key))) {
if (!(error = pack_row(&row, new_row, 0))) { if (!(error = pack_row(&row, new_row))) {
if ((error = file->put(file, trans, new_key, &row, key_type[primary_key]))) { if ((error = file->put(file, trans, new_key, &row, key_type[primary_key]))) {
// Probably a duplicated key; restore old key and row if needed // Probably a duplicated key; restore old key and row if needed
last_dup_key = primary_key; last_dup_key = primary_key;
if (local_using_ignore) { if (local_using_ignore) {
int new_error; int new_error;
if ((new_error = pack_row(&row, old_row, 0)) || (new_error = file->put(file, trans, old_key, &row, key_type[primary_key]))) if ((new_error = pack_row(&row, old_row)) || (new_error = file->put(file, trans, old_key, &row, key_type[primary_key])))
error = new_error; // fatal error error = new_error; // fatal error
} }
} }
...@@ -1719,7 +1717,7 @@ int ha_tokudb::update_primary_key(DB_TXN * trans, bool primary_key_changed, cons ...@@ -1719,7 +1717,7 @@ int ha_tokudb::update_primary_key(DB_TXN * trans, bool primary_key_changed, cons
} }
} else { } else {
// Primary key didn't change; just update the row data // Primary key didn't change; just update the row data
if (!(error = pack_row(&row, new_row, 0))) if (!(error = pack_row(&row, new_row)))
error = file->put(file, trans, new_key, &row, 0); error = file->put(file, trans, new_key, &row, 0);
} }
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
......
...@@ -120,7 +120,7 @@ private: ...@@ -120,7 +120,7 @@ private:
uchar current_ident[TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH]; uchar current_ident[TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH];
ulong max_row_length(const uchar * buf); ulong max_row_length(const uchar * buf);
int pack_row(DBT * row, const uchar * record, bool new_row); int pack_row(DBT * row, const uchar * record);
void unpack_row(uchar * record, DBT * row); void unpack_row(uchar * record, DBT * row);
void unpack_key(uchar * record, DBT * key, uint index); void unpack_key(uchar * record, DBT * key, uint index);
DBT *create_key(DBT * key, uint keynr, uchar * buff, const uchar * record, int key_length = MAX_KEY_LENGTH); DBT *create_key(DBT * key, uint keynr, uchar * buff, const uchar * record, int key_length = MAX_KEY_LENGTH);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment