Commit 1aa6343f authored by unknown's avatar unknown

Simple optimization

nsure that delete works not only on table->record[0] for federated tables


sql/field.cc:
  Test OOM condition
sql/ha_federated.cc:
  Simple optimizations
  Ensure that delete works not only on table->record[0]
sql/opt_range.cc:
  Simplify code
parent feffe571
...@@ -6822,7 +6822,12 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -6822,7 +6822,12 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
&not_used))) &not_used)))
{ {
uint conv_errors; uint conv_errors;
tmpstr.copy(from, length, cs, field_charset, &conv_errors); if (tmpstr.copy(from, length, cs, field_charset, &conv_errors))
{
/* Fatal OOM error */
bzero(ptr,Field_blob::pack_length());
return -1;
}
from= tmpstr.ptr(); from= tmpstr.ptr();
length= tmpstr.length(); length= tmpstr.length();
if (conv_errors) if (conv_errors)
......
...@@ -1399,27 +1399,25 @@ int ha_federated::update_row(const byte *old_data, byte *new_data) ...@@ -1399,27 +1399,25 @@ int ha_federated::update_row(const byte *old_data, byte *new_data)
int ha_federated::delete_row(const byte *buf) int ha_federated::delete_row(const byte *buf)
{ {
uint x= 0;
char delete_buffer[IO_SIZE]; char delete_buffer[IO_SIZE];
char data_buffer[IO_SIZE]; char data_buffer[IO_SIZE];
String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin); String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin);
delete_string.length(0);
String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin); String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin);
data_string.length(0);
DBUG_ENTER("ha_federated::delete_row"); DBUG_ENTER("ha_federated::delete_row");
delete_string.length(0);
delete_string.append("DELETE FROM `"); delete_string.append("DELETE FROM `");
delete_string.append(share->table_base_name); delete_string.append(share->table_base_name);
delete_string.append("`"); delete_string.append("`");
delete_string.append(" WHERE "); delete_string.append(" WHERE ");
for (Field **field= table->field; *field; field++, x++) for (Field **field= table->field; *field; field++)
{ {
delete_string.append((*field)->field_name); Field *cur_field= *field;
data_string.length(0);
delete_string.append(cur_field->field_name);
if ((*field)->is_null()) if (cur_field->is_null_in_record((const uchar*) buf))
{ {
delete_string.append(" IS "); delete_string.append(" IS ");
data_string.append("NULL"); data_string.append("NULL");
...@@ -1427,17 +1425,15 @@ int ha_federated::delete_row(const byte *buf) ...@@ -1427,17 +1425,15 @@ int ha_federated::delete_row(const byte *buf)
else else
{ {
delete_string.append("="); delete_string.append("=");
(*field)->val_str(&data_string); cur_field->val_str(&data_string, (char*) buf+ cur_field->offset());
(*field)->quote_data(&data_string); cur_field->quote_data(&data_string);
} }
delete_string.append(data_string); delete_string.append(data_string);
data_string.length(0); delete_string.append(" AND ");
if (x + 1 < table->s->fields)
delete_string.append(" AND ");
} }
delete_string.length(delete_string.length()-5); // Remove AND
delete_string.append(" LIMIT 1"); delete_string.append(" LIMIT 1");
DBUG_PRINT("info", DBUG_PRINT("info",
("Delete sql: %s", delete_string.c_ptr_quick())); ("Delete sql: %s", delete_string.c_ptr_quick()));
......
...@@ -8556,23 +8556,21 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range() ...@@ -8556,23 +8556,21 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range()
if ((result == HA_ERR_KEY_NOT_FOUND) && (cur_range->flag & EQ_RANGE)) if ((result == HA_ERR_KEY_NOT_FOUND) && (cur_range->flag & EQ_RANGE))
continue; /* Check the next range. */ continue; /* Check the next range. */
else if (result) if (result)
{
/* /*
In no key was found with this upper bound, there certainly are no keys In no key was found with this upper bound, there certainly are no keys
in the ranges to the left. in the ranges to the left.
*/ */
return result; return result;
}
/* A key was found. */ /* A key was found. */
if (cur_range->flag & EQ_RANGE) if (cur_range->flag & EQ_RANGE)
return result; /* No need to perform the checks below for equal keys. */ return 0; /* No need to perform the checks below for equal keys. */
/* Check if record belongs to the current group. */ /* Check if record belongs to the current group. */
if (key_cmp(index_info->key_part, group_prefix, real_prefix_len)) if (key_cmp(index_info->key_part, group_prefix, real_prefix_len))
{ continue; // Row not found
result = HA_ERR_KEY_NOT_FOUND;
continue;
}
/* If there is a lower limit, check if the found key is in the range. */ /* If there is a lower limit, check if the found key is in the range. */
if ( !(cur_range->flag & NO_MIN_RANGE) ) if ( !(cur_range->flag & NO_MIN_RANGE) )
......
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