Commit 62e7ad2b authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: move initializations from query exec to prepare time

that is don't call alloc_lookup_buffer() and create_lookup_handler()
for every row

also, don't call ha_check_overlaps() for every partition,
after it was already done on the ha_partition level
parent 259fb1cb
...@@ -6737,26 +6737,20 @@ int handler::check_duplicate_long_entries_update(const uchar *new_rec) ...@@ -6737,26 +6737,20 @@ int handler::check_duplicate_long_entries_update(const uchar *new_rec)
int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
{ {
DBUG_ASSERT(new_data); DBUG_ASSERT(new_data);
if (this != table->file)
return 0;
if (!table_share->period.unique_keys) if (!table_share->period.unique_keys)
return 0; return 0;
if (table->versioned() && !table->vers_end_field()->is_max()) if (table->versioned() && !table->vers_end_field()->is_max())
return 0; return 0;
bool is_update= old_data != NULL; const bool is_update= old_data != NULL;
alloc_lookup_buffer(); uchar *record_buffer= lookup_buffer + table_share->max_unique_length
auto *record_buffer= lookup_buffer + table_share->max_unique_length + table_share->null_fields;
+ table_share->null_fields;
auto *handler= this;
// handler->inited can be NONE on INSERT
if (handler->inited != NONE)
{
create_lookup_handler();
handler= lookup_handler;
// Needs to compare record refs later is old_row_found() // Needs to compare record refs later is old_row_found()
if (is_update) if (is_update)
position(old_data); position(old_data);
}
DBUG_ASSERT(!keyread_enabled()); DBUG_ASSERT(!keyread_enabled());
...@@ -6780,11 +6774,11 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) ...@@ -6780,11 +6774,11 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
continue; continue;
} }
error= handler->ha_index_init(key_nr, 0); error= lookup_handler->ha_index_init(key_nr, 0);
if (error) if (error)
return error; return error;
error= handler->ha_start_keyread(key_nr); error= lookup_handler->ha_start_keyread(key_nr);
DBUG_ASSERT(!error); DBUG_ASSERT(!error);
const uint period_field_length= key_info.key_part[key_parts - 1].length; const uint period_field_length= key_info.key_part[key_parts - 1].length;
...@@ -6801,7 +6795,7 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) ...@@ -6801,7 +6795,7 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
period_field_length); period_field_length);
/* Find row with period_end > (period_start of new_data) */ /* Find row with period_end > (period_start of new_data) */
error = handler->ha_index_read_map(record_buffer, lookup_buffer, error = lookup_handler->ha_index_read_map(record_buffer, lookup_buffer,
key_part_map((1 << (key_parts - 1)) - 1), key_part_map((1 << (key_parts - 1)) - 1),
HA_READ_AFTER_KEY); HA_READ_AFTER_KEY);
...@@ -6814,13 +6808,13 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) ...@@ -6814,13 +6808,13 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
An assumption is made that during update we always have the last An assumption is made that during update we always have the last
fetched row in old_data. Therefore, comparing ref's is enough fetched row in old_data. Therefore, comparing ref's is enough
*/ */
DBUG_ASSERT(handler != this); DBUG_ASSERT(lookup_handler != this);
DBUG_ASSERT(inited != NONE); DBUG_ASSERT(inited != NONE);
DBUG_ASSERT(ref_length == handler->ref_length); DBUG_ASSERT(ref_length == lookup_handler->ref_length);
handler->position(record_buffer); lookup_handler->position(record_buffer);
if (memcmp(ref, handler->ref, ref_length) == 0) if (memcmp(ref, lookup_handler->ref, ref_length) == 0)
error= handler->ha_index_next(record_buffer); error= lookup_handler->ha_index_next(record_buffer);
} }
if (!error && table->check_period_overlaps(key_info, new_data, record_buffer)) if (!error && table->check_period_overlaps(key_info, new_data, record_buffer))
...@@ -6832,10 +6826,10 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data) ...@@ -6832,10 +6826,10 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
if (error == HA_ERR_FOUND_DUPP_KEY) if (error == HA_ERR_FOUND_DUPP_KEY)
lookup_errkey= key_nr; lookup_errkey= key_nr;
int end_error= handler->ha_end_keyread(); int end_error= lookup_handler->ha_end_keyread();
DBUG_ASSERT(!end_error); DBUG_ASSERT(!end_error);
end_error= handler->ha_index_end(); end_error= lookup_handler->ha_index_end();
if (!error && end_error) if (!error && end_error)
error= end_error; error= end_error;
} }
...@@ -6919,7 +6913,7 @@ bool handler::prepare_for_row_logging() ...@@ -6919,7 +6913,7 @@ bool handler::prepare_for_row_logging()
int handler::prepare_for_insert() int handler::prepare_for_insert()
{ {
/* Preparation for unique of blob's */ /* Preparation for unique of blob's */
if (table->s->long_unique_table) if (table->s->long_unique_table || table->s->period.unique_keys)
{ {
/* /*
When doing a scan we can't use the same handler to check When doing a scan we can't use the same handler to check
...@@ -6941,9 +6935,8 @@ int handler::ha_write_row(const uchar *buf) ...@@ -6941,9 +6935,8 @@ int handler::ha_write_row(const uchar *buf)
DBUG_ENTER("handler::ha_write_row"); DBUG_ENTER("handler::ha_write_row");
DEBUG_SYNC_C("ha_write_row_start"); DEBUG_SYNC_C("ha_write_row_start");
error= ha_check_overlaps(NULL, buf); if ((error= ha_check_overlaps(NULL, buf)))
if (unlikely(error)) DBUG_RETURN(error);
goto end;
MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str); MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str);
mark_trx_read_write(); mark_trx_read_write();
...@@ -6976,7 +6969,6 @@ int handler::ha_write_row(const uchar *buf) ...@@ -6976,7 +6969,6 @@ int handler::ha_write_row(const uchar *buf)
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */
} }
end:
DEBUG_SYNC_C("ha_write_row_end"); DEBUG_SYNC_C("ha_write_row_end");
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
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